【问题标题】:Prevent inclusion of mean in boxplot legend防止在箱线图图例中包含平均值
【发布时间】:2013-09-03 21:24:45
【问题描述】:

在增加均值的 ggplot2 箱线图中,有没有办法防止均值 包括在传说中?我必须使用大点大小并找到它 包含在传说中分散注意力。概念上最接近的问题 我可以发现,为了从 outlined 条形图的图例中删除斜线,是 在

http://www.cookbook-r.com/Graphs/Legends_(ggplot2)/#modifying-the-legend-box

该解决方案使用 geom_bar 两次将一个图覆盖在另一个图上,第二个,概述 条形图,没有图例。但是有没有办法防止 出现在箱线图图例中的平均值?

ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot() +
stat_summary(fun.y=mean, colour="darkred", geom="point", shape=18, size=3) + 
#  idea from above website
geom_boxplot(show_guide=FALSE)

【问题讨论】:

    标签: r ggplot2 boxplot legend-properties


    【解决方案1】:

    您可以在 stat_summary() 调用中添加参数 show_guide=FALSE 以防止在图例中放置点。

    ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot() +
      stat_summary(fun.y=mean, colour="darkred", geom="point", 
                             shape=18, size=3,show_guide = FALSE)
    

    【讨论】:

      【解决方案2】:

      如果您想从箱线图图例中删除形状并将其作为新图例添加到图中,则可以使用:

      ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group))+ 
      geom_boxplot() + 
      stat_summary(fun.y=mean, aes(colour="mean"), geom="point", shape=18, size=3)+
      scale_color_manual(name="",values = "darkred")+
      scale_fill_nejm(name="Group",guide=guide_legend(override.aes = list(shape="")))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-21
        • 2021-11-25
        • 2012-08-31
        • 2011-01-30
        • 2021-07-01
        • 2023-04-03
        • 1970-01-01
        • 2011-04-19
        相关资源
        最近更新 更多