I am trying to connecting the median values of a boxplot using ggplot2, but the lines are not in the correct positions.
Here is the code I used.
library(datasets)
library(ggplot2)
data(airquality)
airquality$Month <- factor(airquality$Month,
labels = c("May", "Jun", "Jul", "Aug", "Sep"))
airquality$Day <- ifelse(airquality$Day >= 15, 'End', 'Begining')
ggplot(airquality, aes(x = Month, y = Ozone, fill = Day)) +
geom_boxplot() +
stat_summary(fun.y = median, geom = 'line', aes(group = Day, colour =Day))
The lines are just showing in the plot but not connecting the median values which is what I want.
Any help will be appreciated.