Reputation: 34031
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.
Upvotes: 27
Views: 101488
Reputation: 21630
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()
Upvotes: 27
Reputation:
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)
Upvotes: 5
Reputation: 43450
I usually use
par(mar=c(1,1,1,1))
when I keep the border to a minimum.
Upvotes: 3
Reputation: 44351
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. :-)
Upvotes: 15