Combine geom_boxplot with geom_line

ggplot2, r

Solution

... +  geom_line(aes(group = g))

Problem

I would like to combine a boxplot and a line plot using `ggplot2`. However, I am struggling to have lines for each group (`g`) connecting points across the categories on the x-axis. To demonstrate the problem: ``` df <- data.frame(x = rep(letters[1:3],each=5), y = c(1:5,sample(10,5),1:5), g = rep(LETTERS[1:5],3) ) library(ggplot2) ggplot(df, aes(x=x,y=y)) + geom_boxplot() + geom_point(aes(colour = g)) ``` I want to have a line connecting all `A` points, a line connecting all `B` points and so on. I have looked at some answers here but I cannot incorporate them. They suggest using `group=1` but this will not suit my individual lines for each group in `g`. Is it possible using `stat_summary` maybe?

Original source