I would like to make a boxplot with numerical x ("age") fixed into ranges. For example, I want to have each box for x range of "1-5", "5-10", "10-13", "13-20", ">20", and connecting median values of boxes with a line. If possible, I further want to make such boxplot by function of "season" (a series of boxes for each season in a different frame). My data is as below.
season age value1 value2
wet.summer 14.193 16.786 22.66
fall 3.944 6.432 10.272
fall 9.994 16.111 22.737
fall 3.101 6.507 14.372
winter 2.631 NA 13.889
winter 20.746 22.629 29.27
winter 15.93 21.356 36.454
winter 7.384 7.419 11.851
spring 22.955 25.793 42.038
spring 10.876 16.532 24.188
spring 25.724 27.272 50.447
early.summer 10.825 16.452 23.147
The below is what I used for making another type of boxplot. I tried to modify this to what I want, but failed. Thank you very much for your help!!! :)
p<-ggplot(mydata, aes(factor(age), value1))
p + geom_boxplot(aes(fill = factor(season)))+ stat_summary(fun.y=median, geom="line", aes(group=1)) +
stat_summary(fun.y=median, geom="point")+ scale_x_discrete(breaks=seq(0,30, by=1))+ theme(legend.position=c(.1, .9))+ theme(legend.text = element_text(colour="black", size = 14, face = "bold"))
