当coord_fixed()
与GGPLOT2使用,它不会似乎是可以设置整个情节的背景颜色。考虑以下简单示例:
library(ggplot2)
test_data <- data.frame(x=1:10)
test_data$y <- sqrt(test_data$x)
p1 <- ggplot(test_data) + geom_point(aes(x, y))
p1
Run Code Online (Sandbox Code Playgroud)
我可以轻松地使背景成为另一种颜色,例如扎眼的绿色:
p1 + theme(plot.background=element_rect(fill="green"))
Run Code Online (Sandbox Code Playgroud)
但是,如果我想使用coord_fixed()并将背景颜色设置为绿色怎么办?当我尝试时,这ggplot2
会在情节的底部和顶部留下一条白色的条:
p1 + theme(plot.background=element_rect(fill="green")) + coord_fixed()
Run Code Online (Sandbox Code Playgroud)
如何完全填充上述图的背景(顶部和底部没有白色条纹)?我正在循环使用该animation
包来制作多个子图,并且需要确保所有子图的背景是相同的(非白色)颜色,包括我需要使用的颜色coord_fixed()
。
我使用grid.arrange
的gridExtra
包放在一个页面上两张图,并将其保存为PNG文件.我喜欢更改生成的最终png文件的背景颜色grid.arrange
.可能吗?我无法遇到任何信息.
grid.arrange(p1, p2, main=textGrob("CPU Util", gp=gpar(cex=1.2, fontface="bold", col="#990000")), ncol = 1, clip=TRUE)
Run Code Online (Sandbox Code Playgroud)