Using stat_summary to get mean & ci onto a plot along with a box plot
p1 <- ggplot(data=df, aes(x=group, y=metric ) ) +
geom_boxplot(outlier.shape = NA, fill = fill, color=line, alpha = 0.5) +
stat_summary(fun.data=mean_cl_normal, aes(color = "Mean and CI"))
Beyond this , I also have a requirement to limit the y-axis to avoid displaying values beyond a range. This is done via
p1 <- p1 + scale_y_continuous(limits =c(lower.limit,upper.limit) )
However, the observation is that when the limits are applied, the mean value as shown in the plot is different from the case where limits are not applied. Is this the way it is expected to work ? It seems like stat_summary only includes the points within the limits applied via scale_y_continuous
Is there a way I can get the mean & ci using stat_summary
including the points outside the limits in the plot even when axis limits are applied ?