Search code examples
rggplot2legendoffsetjitter

Offset/jitter (?) legend in dotplot


I'm likely not using the correct terminology, but the issue is that when creating a dotplot that uses pointrange and multiple groups, the groups as defined in the legend is indistinguishable because the pointrange covers the color of each group (see red rectangle in figure). Is there anyway to either remove the pointrange in the legend (or another solution). enter image description here

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)

Thanks for your time.


Solution

  • Try this. You can enable show.legend = F in the last part of your code so that the element will not appear in the legend. Here the code (No output showed as no data was shared):

    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)