在ggplot2箱线图中用均值线替换中位数线
移除箱线图中位数线,仅保留均值线的解决方案
要实现只显示均值线、彻底去掉箱线图默认的中位数线,只需要在geom_boxplot()里添加控制中位数线的参数即可,修改后的最简代码如下:
ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot(median.linewidth = 0) + # 将中位数线宽度设为0,彻底隐藏 stat_summary(fun=mean, geom="errorbar", mapping = aes(ymin = ..y.., ymax = ..y..), width = 0.75, color = "red", size = 1)
你也可以用median.colour = NA替代median.linewidth = 0,把中位数线设为透明色,同样能达到隐藏效果。
内容的提问来源于stack exchange,提问作者johnymm
相关产品推荐
相关产品推荐

