Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plots without titles/labels in R

Tags:

In R is there any way to produce plots which have no title and which use the space the title would otherwise have taken up?

In plot(), main, sub, xlab, and ylab all default to NULL, but this just leaves blank space where they would have been, ditto for setting them to ''. It would be nice if not including them meant that the entire plot space was utilized rather than leaving extra empty space on the edges. This is all especially relevant in printing plots to file devices like pdf(), png(), etc.

like image 620
blahdiblah Avatar asked Apr 10 '09 02:04

blahdiblah


People also ask

How do I turn off axis labels in R?

When we create a plot in R, the Y-axis labels are automatically generated and if we want to remove those labels, the plot function can help us. For this purpose, we need to set ylab argument of plot function to blank as ylab="" and yaxt="n" to remove the axis title.

How do I label a plot in R?

Use the title( ) function to add labels to a plot. Many other graphical parameters (such as text size, font, rotation, and color) can also be specified in the title( ) function. # labels 25% smaller than the default and green.

Which method should be used to change the title of a plot?

Directly by specifying the titles to the plotting function (ex : plot() ). In this case titles are modified during the creation of plot. the title() function can also be used. It adds titles on an existing plot.

How do I add axis labels in R?

To set labels for X and Y axes in R plot, call plot() function and along with the data to be plot, pass required string values for the X and Y axes labels to the “xlab” and “ylab” parameters respectively. By default X-axis label is set to “x”, and Y-axis label is set to “y”.


2 Answers

See tip 7 about adjusting the margins.

Excerpt:

To remove the space reserved for labels, use par(mar=...). For example

png(file="notitle.png",width=400, height=350) par(mar=c(5,3,2,2)+0.1) hist(rnorm(100),ylab=NULL,main=NULL) dev.off() 
like image 170
ojblass Avatar answered Nov 02 '22 12:11

ojblass


If you're willing to entertain an alternate plotting package, ggplot2 does this automatically when you set xlab/ylab to NULL (and there is no plot title/main by default). For simple plots, just require(ggplot2) and replace plot by qplot.

Really, ggplot2 is the most fun I've had with plotting in years and I can't resist the opportunity to evangelize it to everyone I meet. :-)

like image 32
Nicholas Riley Avatar answered Nov 02 '22 11:11

Nicholas Riley