问题描述
我可能没有使用正确的术语,但是问题在于,当创建使用点范围和多个组的点图时,图例中定义的组是无法区分的,因为该点范围覆盖了每个组的颜色(请参见红色图中的矩形)。无论如何,有没有要删除图例中的指针范围(或其他解决方案)。
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)