Boxplot for each individual level in two factor columns?
This is my code. I have two factor variables ( cyl
and am
)that I want to plot in my box plot.
boxplot(mpg~cyl+am,data=mtcars)
I want to make a boxplot for each individual factor levels - 4,6,8,0,1 but not the interaction of them (eg 4.0).
My box plot should only have (4,6,8,0,1) on the axis. How do I do that?
You may reshape the data and then you can do the plotting, However this may not be the elegant
library(reshape2)
mtcars_subset <- mtcars[,c("am", "cyl", "mpg")]
dat <- melt(mtcars_subset, id.vars="mpg")
#or dat <- melt(mtcars, id.vars = "mpg", measure.vars = c("cyl", "am"))
boxplot(data=dat, mpg ~ value)
链接地址: http://www.djcxy.com/p/24846.html
上一篇: 如何交替连接3个字符串