【发布时间】:2017-04-11 15:17:56
【问题描述】:
我想为用作 ggplot 背景的 rastergrob 对象添加透明度。
这是我的代码
library(ggplot2)
library(grid)
library(ggthemes)
reds <- c("brown", "red","orange","green","orange","red","brown","grey")
g <- rasterGrob(reds, width = unit(1, "npc"), height = unit(1,"npc"),interpolate = TRUE)
p <- ggplot(data = economics, aes(x = date, y = unemploy)) +
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)+
geom_line( alpha=1, color = "white", size = 0.5 ) +
xlab("Years") + ylab("Unemployed [thousands]") +
theme_base() +
theme(panel.background=element_blank(),
plot.background=element_blank(),
line = element_line(colour="white")) +
theme()
grid.newpage()
print(p, newpage = FALSE)
我无法在 rastergrob 中添加 alpha,在 annotation_custom 中也没有。我已经找了一段时间了。
【问题讨论】:
-
您尝试过使用数值吗?例如。而不是“红色”使用“#F5262688”
-
嗯,是的,我找到了“adjustcolor”函数,它可以将我的向量的所有颜色转换为透明的等价物。谢谢!
-
也许您可以发布自己问题的答案,以便人们知道该问题已得到解答。
标签: r ggplot2 background transparency