gpt4 book ai didi

R:使用 Alpha 控制填充

转载 作者:行者123 更新时间:2023-12-02 06:08:45 24 4
gpt4 key购买 nike

我正在尝试使用 Alpha 来控制图形填充的透明度。我知道 alpha 函数已移至 scales 包中,但我仍然无法使其工作。

数据集:

library(scales)
library(ggplot2)
Groups <- data.frame(Level=c("High", "Above Average", "Average", "Below Average", "Low"),
Start=c(7.5, 5.5, 4.5, 2.5, .5), End=c(11.5, 7.5, 5.5, 4.5, 2.5))
Groups$Start<-as.numeric(as.character(Groups$Start))

d <- data.frame(x=1:10, y=1:10)

basicBox <- ggplot(d, aes(factor(x), y)) + geom_boxplot()
basicBox +
geom_rect(aes(NULL, NULL, xmin=Start, xmax=End, fill=Level), ymin=0, ymax=20, data=Groups) +
scale_fill_manual(values=alpha(c("red", "blue", "green", "grey", "purple"), 0.2))

类似的代码可以在 Hadley Wickham 的 ggplot2 第 86 页上找到。当我不加载比例库时,我收到错误消息说 R 无法识别 alpha 函数,但即使在加载比例之后,我也无法让 alpha 正常工作。

最佳答案

如果我明白你的要求,它应该是这样的:

basicBox + 
geom_rect(aes(NULL, NULL, xmin=Start, xmax=End, fill=Level),
ymin=0, ymax=20, data=Groups, alpha=0.2) +
scale_fill_manual(values=c("red", "blue", "green", "grey", "purple"))

我将 alpha 参数放入 geom_rect 中,但没有将其用作函数。

关于R:使用 Alpha 控制填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11067462/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com