简体   繁体   中英

How to separate boxplots in r?

I have to plot a boxplot for the PM2.5 levels when the rain > 0 for 12 noon. I've used the code:

boxplot(PM2.5~RAIN, data=subset(dat, RAIN > 0 & hour == 12), range = 0)

But it comes up with several boxplots (eg one boxplot for 0.1 mm rain, another for 0.2 mm rain)

Any help with separating these boxplots would be appreciated.

One way is to create a constant in the data and then use that on the right-hand side.

dat$CONSTANT <- 0
boxplot(PM2.5~CONSTANT, data=subset(dat, RAIN > 0 & hour == 12), range = 0)

Another option is to create a subset first.

with(subset(dat, RAIN > 0 & hour == 12),
    boxplot(PM2.5, range = 0) )

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