Reputation: 15
The code I used to get this boxplot from the "Cars" data is as follows:
boxplot(Economy_highway ~ Cylinders,data = Cars, main="Box Plot",ylab="cylinders", xlab="highway_economy",horizontal=TRUE, col = "skyblue")
My question is, how do we subset the cylinders 4 & 6 vs Economy_highway?
I have tried several subsetting codes but still unsuccessful.
Upvotes: 0
Views: 13871
Reputation: 93813
boxplot
has a subset=
argument, so, with a reproducible example you can do something like:
boxplot(mpg ~ cyl, data=mtcars, subset=cyl %in% c(4,6))
Which I think for your full example translates to:
boxplot(Economy_highway ~ Cylinders,data = Cars,subset=Cylinders %in% c(4,6), main="Box Plot", ylab="cylinders", xlab="highway_economy",horizontal=TRUE, col = "skyblue")
Upvotes: 2