我正在尝试使用alpha来控制图形填充的透明度.我知道alpha函数已被移动到scale包,但我仍然无法使它工作.
数据集:
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))
Run Code Online (Sandbox Code Playgroud)
类似的代码可以在Hadley Wickham的ggplot2的第86页找到.当我没有加载scale库时,我得到并且错误地说R不能识别alpha函数,但即使在我加载了scale之后我也无法使alpha工作正常.
Jar*_*red 10
如果我得到你所要求的,它应该是这样的:
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"))
Run Code Online (Sandbox Code Playgroud)
我把alpha参数放入geom_rect,并没有将它用作函数.
| 归档时间: |
|
| 查看次数: |
8941 次 |
| 最近记录: |