[英]ggplot2 legend for stat_summary
如何创建一个图例,告知红十字是平均值?
ggplot(results, aes(x=factor, y=proportionPositive)) +
geom_boxplot() +
stat_summary(fun.data = "mean_cl_normal", colour = "red", shape=4)
这是一种方法:
# Create dummy data results <- data.frame( factor=factor(rep(1:10, 100)), proportionPositive=rnorm(1000)) # Plot results ggplot(results, aes(x=factor, y=proportionPositive)) + geom_boxplot() + stat_summary(fun.data = "mean_cl_normal", aes(shape="mean"), colour = "red", geom="point") + scale_shape_manual("", values=c("mean"="x"))
对我来说,选项“show.legend=TRUE”确实有效:
ggplot(aes(x=stimulus, y=EPN, fill=strategy))+
stat_summary(fun.data=mean_se, show.legend=TRUE, geom="bar", position="dodge", colour="black", linetype="solid", size=0.3)
使它看起来像一个默认图例(借用@Andrie代码):
ggplot(results, aes(x=factor, y=proportionPositive)) +
geom_boxplot() +
stat_summary(fun.data = "mean_cl_normal",
aes(shape=""), # Leave empty
colour = "red",
geom="point") +
scale_shape_manual("mean", values= "") # Will show mean on top of the line
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.