[英]manually editing color of confidence intervals and mean across ggplot2 facets
I can choose the color of my confidence intervals in ggplot, but it fails when I try to plot these intervals in different facets.我可以在 ggplot 中选择置信区间的颜色,但是当我尝试在不同方面对这些区间进行 plot 时,它会失败。
This works as expected这按预期工作
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"))
But when i try to plot that in facets, it doesn't plot the two ribbons with their colors per facet.但是当我尝试在方面 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")
and comes the error: Error: Aesthetics must be either length 1 or the same as the data (4): colour Run rlang::last_error()
to see where the error occurred.并出现错误:错误:美学必须是长度 1 或与数据相同 (4): color 运行rlang::last_error()
以查看错误发生的位置。
Adding添加
scale_fill_manual(values=c("turquoise", "orange")) +
did not help either.也没有帮助。
What could be the work around?可以解决什么问题?
Just change:只是改变:
colour=c("turquoise", "orange")
to至
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.