简体   繁体   中英

Boxplot with geom_boxplot for many years

I want to make nice boxplot with ggplot2. NB: the airquality data from ggplot2 can illustrated what I want to do but in my own data I have an additional column for year(1900:2000).

I make simple boxplot with this command:

      tapply(data$Temp, substr(data$Month, 1,3),na.rm=TRUE, summary) #data=airquality
      boxplot(Temp~Month, data=data, na.action = NULL, main="1900-2000")

It have this graphic: Graph1

But I when try with ggplot2 with this command:

     ggplot(data, aes(Month, Temp),facet= Month~.) + geom_boxplot()

It get this graphic Graph2

In the same plot I want to view the corresponding Value and boxplot for each month like graphic1

Because Month is a continuous variable you will need to 'factorize' this variable to have seperate boxplots:

ggplot(airquality, aes(factor(Month), Temp)) + geom_boxplot()

alternatively you can use the group aesthetic:

ggplot(airquality, aes(Month, Temp, group = Month)) + geom_boxplot()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM