Add ribbon showing mean and interquartile range to ggplot2

by Hedgehog   Last Updated January 08, 2018 03:26 AM

I use the following example data and code

# Example
df <- data.frame(a=runif(100),b=runif(100),c=runif(100))
df$Metric <- ifelse(df$a > 0.5,"a", "b")

df$Methodology <- ifelse(df$a > 0.5,"One", "Two")
df$Methodology <- factor(df$Methodology)

pl<-df %>%
  group_by(Methodology) %>%
    plots = ggplot(data=., aes(x = a, y = b)) +
              geom_point() +
              stat_smooth(method="auto",size=1.5) +
              stat_summary(, fun.args=( + # Show IQR
              facet_wrap(~Metric, scales="free") +

The output I see is:

enter image description here

However, I would also like to also see another ribbon plot showing the inter quartile range calculated by stat_summary, as well as a line showing the median value.

I suspect I will have to write a user defined function and play with that.

Appreciate any hints or tips.

Tags : r ggplot2

Related Questions

R - How to find points within specific Contour

Updated May 28, 2015 23:11 PM

How to see the code of a stored plot (ggplot)

Updated May 29, 2015 01:11 AM

R ggplot remove certain items from legend

Updated April 03, 2015 23:11 PM

add second axis label

Updated April 10, 2015 23:11 PM

Error in facet_grid in ggplot2

Updated October 09, 2016 09:11 AM