element_blank doesn't seem to make panel.background blank when using gridExtra

309 views
Skip to first unread message

Scott Chamberlain

unread,
Sep 12, 2012, 4:37:03 PM9/12/12
to ggp...@googlegroups.com
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  
Rplot03.png

Brandon Hurr

unread,
Sep 12, 2012, 4:50:18 PM9/12/12
to Scott Chamberlain, ggp...@googlegroups.com
Even setting everything to NA doesn't work...

a <- ggplot(mtcars, aes(mpg, cyl)) +
geom_point() +
theme(panel.background = element_rect(fill = NA), panel.border= element_rect(fill=NA))


b <- ggplot(mtcars, aes(disp)) +
geom_histogram() +
theme(panel.background = element_rect(fill = NA), panel.border= element_rect(fill=NA))

It's the plot.background that is actually causing the issue though. 

theme(panel.background = element_blank(),  panel.border= element_blank(), and plot.background = element_blank())

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Scott Chamberlain

unread,
Sep 12, 2012, 4:58:23 PM9/12/12
to ggp...@googlegroups.com, Scott Chamberlain
Ahhh, I see now. In the previous ggplot2 version I only needed panel.background = theme_blank(). 

Thanks, S
Reply all
Reply to author
Forward
0 new messages