views:

470

answers:

4

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.

+3  A: 

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()
ojblass
+4  A: 

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. :-)

Nicholas Riley
+1 for getting excited about plotting
ojblass
A: 

I usually use

par(mar=c(1,1,1,1))

when I keep the border to a minimum.

Christopher DuBois
A: 

With lattice, it's just a matter of setting the xlab, ylab, and main arguments to NULL:


library(lattice)
bwplot(rnorm(100),xlab=NULL,ylab=NULL,main=NULL)