【发布时间】:2023-04-03 19:35:01
【问题描述】:
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
我可以轻松地将背景设置为另一种颜色,例如鲜艳的绿色:
p1 + theme(plot.background=element_rect(fill="green"))
但是如果我想使用 coord_fixed() 并将背景涂成绿色怎么办?当我尝试这个ggplot2 在图的底部和顶部留下一条白色条带时:
p1 + theme(plot.background=element_rect(fill="green")) + coord_fixed()
如何完全填充上图的背景(没有顶部和底部的白条)?我在一个循环中生成了许多子图以与animation 包一起使用,我需要确保所有子图的背景都是相同的(非白色)颜色,包括我需要在其上使用@ 987654330@.
【问题讨论】: