我已经用ggplot2制作了几个简单的图,并用grid.arrange()
(来自包grid.extra)将它们分组,以便在一个图中加入图。
我通过带有参数grid.arrange()
的{{1}}函数创建标题,如下所示:
top
...
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()
添加)从ggplot主题获取背景而不是像边缘一样白。
我尝试过使用参数top
,但没有效果。
如何在白色背景上获得标题?
我知道使用fill
会更直接并避免facets
,但在这种情况下它没有意义。我想我也可以将grid.arrange
主题更改为白色,但在这种情况下,这不是一个选项。
感谢
答案 0 :(得分:2)
正如user20650所说,这是一个打印问题。 以下两个选项都有效。
首先将图形保存为R对象和tiff文件:
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()
或者,仅保存tiff文件,如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()