Annotate outliers in ggplot boxplot

Hi,
This post is somehow connected with that solved post:
https://forum.posit.co/t/mean-and-median-in-one-boxplot/148382/13

I would like to add description of outliers to this plot:

smry_text <- PlantGrowth |> 
  group_by(group) |> 
  summarise(across(.cols=weight,
                   .fns = list(mean=mean,median=median))) |> 
  mutate(mean_text = paste0("Mean : ",weight_mean),
         median_text = paste0("\n\nMedian : ",weight_median))

ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) +
  geom_boxplot() +
  stat_summary(fun=mean, color="darkred",geom="crossbar", show.legend=TRUE)  +
  geom_text(data = smry_text, aes(label = median_text,
                                   y=weight_mean),
             ,nudge_y = -.2) +
  geom_text(data = smry_text, aes(label = mean_text,
                                   y=weight_mean),
             ,nudge_y = -.2,color="darkred" , fontface = "bold")

I would like to add horizontal lines to whiskers as well.
My previous attempts are documented in forementioned linked above post.
Thank you for your help, ideas.

for outlier labelling, this seems a reasonable basis :
stackoverflow/geom_boxplot
for top and bottom whiskers maybe use the existing approach but with min and max

   stat_summary(fun=mean, color="darkred",geom="crossbar", show.legend=TRUE)  +
    stat_summary(fun=min, color="black",geom="crossbar", show.legend=TRUE,size=.1)  +
    stat_summary(fun=max, color="black",geom="crossbar", show.legend=TRUE,size=.1)  +

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.