Title background with grid.arrange() of ggplot objects

I've made a couple of simple plots with ggplot2 and grouped them with grid.arrange() (from package grid.extra) to join the plots in one single figure. I'm creating the title via the grid.arrange() function with argument top , as below:

library(ggplot2)
library(gridExtra)

...

tiff("Figure5.tiff",
     height = 20, width = 16, units = "cm", 
     compression = "lzw", res = 300)
Fig5 <- grid.arrange(plot5, plot5Ran, ncol = 2,
                     top = textGrob("Comparison of Correlation Output",
                                  gp = gpar(fill='snow')))

plot(Fig5)
dev.off()

部分屏幕截图,标题背景与情节相同,而不是白边

However, as you can see on the partial screenshot above, the background of the title (the portion of the image at the top of the figure, added by argument top , gets the background from the ggplot theme rather than being white like the margins. I've tried using argument fill but to no effect.

How can I get the title over a white background? I know that using facets would be more straightforward and avoid grid.arrange , but it doesn't make sense in this case. I guess that I could also change the ggplot theme to white, but that's not an option in this case. Thanks


As user20650 suggested, it was a printing problem. Both options below work.

First saving the figure as R object and the tiff file:

tiff("Figure5X.tiff",
     height = 20, width = 16, units = "cm", 
     compression = "lzw", res = 300)
Fig5 <- grid.arrange(plot5, plot5Ran, ncol = 2,
                     top = "Comparison of Correlation Output")
Fig5
dev.off()

Or, saving the tiff file only, as suggested by user20650:

tiff("Figure5Y.tiff",
     height = 20, width = 16, units = "cm", 
     compression = "lzw", res = 300)
     grid.arrange(plot5, plot5Ran, ncol = 2,
                     top = "Comparison of Correlation Output")
dev.off()
链接地址: http://www.djcxy.com/p/25032.html

上一篇: 修改CRAN Contributed软件包中的R图形

下一篇: 用ggplot对象的grid.arrange()标题背景