Restrain stat_summary errorbars within specified y-axis range in violin plot (ggplot2)

23 Views Asked by At

I'm creating a violin plot and am wanting to add a

stat_summary 

argument to show the mean and standard deviation/errorbars for each group. However, when I do this, the y-axis is reorientated so that the origin is no longer at 0, as the errorbars go below 0.

A value below 0 doesn't make sense for the data, so I'm wondering if there is a way I can force the axis to start at 0, and crop/restrain the error bars so they remain inside the plot?

The code for my plot:

  ggplot(data=scatrichnessordered, aes(x=ReleaseTime, y=ASVCount, fill=ReleaseTime)) +
    geom_violin(scale="count") +
    theme_bw() +
      theme(panel.border = element_rect(colour = "black", fill=NA, linewidth =.5),axis.line = element_line(colour = "black"))+ ylab("Observed Richness (ASV)") + labs(fill="Release Time")+
   scale_y_continuous(expand = c(0, 0))+
     stat_summary(fun.data=mean_sdl, geom="pointrange", color="black", show.legend = "FALSE")+
    scale_fill_manual(values=c("#fde725","#7ad151", "#31688e"))

Which produces the following, which is what I want apart from the issue with the axis: Violin-Plot

0

There are 0 best solutions below