By popular demand: a more complete problem demonstration:
library(ggplot2)
library(gtable)
# Layout the gtable
# Prepare for the addition of inter-column/row space of 2.5 mm
tmpGTable <- gtable(
widths=unit(x=rep(30,2),units="mm"),
heights=unit(x=rep(30,3),units="mm"),
name="Figure1")
# Add inter-column/raw space
tmpGTable <- gtable_add_col_space(tmpGTable,unit(2.5,units="mm"))
tmpGTable <- gtable_add_row_space(tmpGTable,unit(2.5,units="mm"))
gtable_show_layout(tmpGTable)
tmpB <- ggplot(data=diamonds, aes(carat, price)) +
xlim(0, 2) +
geom_point()
tmpB <- tmpB + theme(plot.margin = unit(c(0,0,0,0), "mm"),plot.background=element_rect(fill="transparent"))
tmpGTable <- gtable_add_grob(x=tmpGTable,grobs=ggplotGrob(tmpB),t=1,l=3)
plot(tmpGTable)
(tmpDir <- tempdir())
png(filename=file.path(tmpDir,"test.png"),width=62.5,height=95,units="mm",res=200)
plot(tmpGTable)
dev.off()
The result on my system is attached. Note the faint grid in the background of the whole plot not the plot.background of the ggplot in the uper right - I'm perfectly fine with that.
My sessionInfo() is:
R version 3.0.1 (2013-05-16)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] gtable_0.1.2 ggplot2_0.9.3.1
loaded via a namespace (and not attached):
[1] colorspace_1.2-2 dichromat_2.0-0 digest_0.6.3 labeling_0.1 MASS_7.3-26
[6] munsell_0.4 plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2
[11] scales_0.2.3 stringr_0.6.2 tools_3.0.1
Thanks, Joh