【问题标题】:Offset/jitter (?) legend in dotplot点图中的偏移/抖动(?)图例
【发布时间】:2020-10-29 21:57:42
【问题描述】:

我可能没有使用正确的术语,但问题是在创建使用点范围和多个组的点图时,图例中定义的组无法区分,因为点范围涵盖了每个组的颜色(见红色图中的矩形)。无论如何要删除图例中的点范围(或其他解决方案)。

p <- ggplot(ToothGrowth, aes(x=dose, y=len, fill = dose)) + geom_dotplot(binaxis='y', stackdir='center', dotsize = .5, alpha = .25)

p + stat_summary(fun.data=mean_sdl,fun.args = list(mult=1),geom="pointrange", color="black", size = 1)

感谢您的宝贵时间。

【问题讨论】:

    标签: r ggplot2 legend offset jitter


    【解决方案1】:

    试试这个。您可以在代码的最后一部分启用show.legend = F,这样该元素就不会出现在图例中。这里的代码(没有输出显示,因为没有数据被共享):

    library(ggplot2)
    #Code
    p <- ggplot(ToothGrowth, aes(x=dose, y=len, fill = dose)) + 
      geom_dotplot(binaxis='y', stackdir='center',
                   dotsize = .5, alpha = .25)
    p + stat_summary(fun.data=mean_sdl,fun.args = list(mult=1),
                     geom="pointrange", color="black", size = 1,show.legend = F)
    

    【讨论】:

      【解决方案2】:

      或者你可以使用guides(fill = FALSE)函数或者scale_fill_discrete(guide = FALSE)

      p + guides(fill = FALSE)
      

      p + scale_fill_discrete(guide = FALSE)
      

      【讨论】:

        猜你喜欢
        • 2023-03-09
        • 2014-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-12
        • 2021-02-09
        • 2021-03-04
        • 2012-10-10
        相关资源
        最近更新 更多