Shouldn't panel.background = element_blank make a blank panel background? It doesn't seem to work for me when trying to layer multiple plots using gridExtra. See example below.
require(ggplot2); require(gridExtra)
a <- ggplot(mtcars, aes(mpg, cyl)) +
geom_point() +
theme(panel.background = element_blank())
b <- ggplot(mtcars, aes(disp)) +
geom_histogram() +
theme(panel.background = element_blank())
grid.newpage()
pushViewport(viewport(layout = grid.layout(2,1)))
vpa_ <- viewport(width = 0.9, height = 0.38, x = 0.5, y = 0.49)
vpb_ <- viewport(width = 0.9, height = 0.38, x = 0.5, y = 0.49)
print(a, vp = vpa_)
print(b, vp = vpb_)
## The attached figure shows the output where the second figure (b) just overlays a, whereas if there was not background wouldn't you be able to see the bottom figure through the top one?
> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] C/en_US.UTF-8/C/C/C/C
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] gridExtra_0.9.1 ggplot2_0.9.2 sacbox_0.0.0 plyr_1.7.1 stringr_0.6.1 knitr_0.7
[7] devtools_0.7.1
loaded via a namespace (and not attached):
[1] MASS_7.3-19 RColorBrewer_1.0-5 RCurl_1.91-1 SparseM_0.96 apTreeshape_1.4-4
[6] ape_3.0-5 bipartite_1.17 calibrate_1.7.1 colorspace_1.1-1 dichromat_1.2-4
[11] digest_0.5.2 evaluate_0.4.2 formatR_0.6 gee_4.13-18 gtable_0.1.1
[16] httr_0.1.1 igraph_0.6-2 labeling_0.1 lattice_0.20-6 memoise_0.1
[21] msm_1.1.1 munsell_0.3 mvtnorm_0.9-9992 nlme_3.1-104 numDeriv_2012.3-1
[26] phytools_0.1-9 proto_0.3-9.2 quantreg_4.81 reshape2_1.2.1 scales_0.2.2
[31] splines_2.15.1 survival_2.36-14 tnet_3.0.7 tools_2.15.1 vegan_2.0-4