[英]manually editing color of confidence intervals and mean across ggplot2 facets
我可以在 ggplot 中选择置信区间的颜色,但是当我尝试在不同方面对这些区间进行 plot 时,它会失败。
这按预期工作
df=data.frame(Effectsize=seq(from=1, to=20, by=1),percentile=as.factor(rep(c("10th","50th"), 10)), name=as.factor(rep(c("Group1","Group2","Group2","Group1","Group1"), 4)))
ggplot(df, aes(y=Effectsize, x=percentile))+xlab("")+ylab("Effect size (Slope/SD)")+
geom_boxplot(fill="transparent", colour="transparent")+
stat_summary(fun = mean, geom = "point", colour=c("turquoise", "orange"))+
stat_summary(fun.data = mean_cl_boot, geom = "errorbar", colour=c("turquoise", "orange"))
但是当我尝试在方面 plot 时,它不是 plot 两个色带,每个方面都有 colors。
ggplot(df, aes(y=Effectsize, x=percentile))+xlab("")+ylab("Effect size (Slope/SD)")+
geom_boxplot(fill="transparent", colour="transparent")+
stat_summary(fun = mean, geom = "point", colour=c("turquoise", "orange"))+
stat_summary(fun.data = mean_cl_boot, geom = "errorbar", colour=c("turquoise", "orange"))+
facet_grid(. ~ name)+theme(legend.position = "none")
并出现错误:错误:美学必须是长度 1 或与数据相同 (4): color 运行rlang::last_error()
以查看错误发生的位置。
添加
scale_fill_manual(values=c("turquoise", "orange")) +
也没有帮助。
可以解决什么问题?
只是改变:
colour=c("turquoise", "orange")
至
colour=c("turquoise", "orange", "turquoise", "orange")
ggplot(df, aes(y=Effectsize, x=percentile))+xlab("")+ylab("Effect size (Slope/SD)")+
geom_boxplot(fill="transparent", colour="transparent")+
stat_summary(fun = mean, geom = "point", colour=c("turquoise", "orange", "turquoise", "orange"))+
stat_summary(fun.data = mean_cl_boot, geom = "errorbar", colour=c("turquoise", "orange", "turquoise", "orange"))+
facet_grid(. ~ name)+
theme(legend.position = "none")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.