[英]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.