Offset/jitter (?) 点图中的图例

Offset/jitter (?) legend in dotplot

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

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,这样该元素就不会出现在图例中。这里的代码(没有输出显示,因为没有共享数据):

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)

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

p + guides(fill = FALSE)

p + scale_fill_discrete(guide = FALSE)