Create boxes for combining categorical variables
2 answers
If you mean one graph versus all combinations of two factors (engine shape (V / S) and cyl), then something like this:
with(mtcars,boxplot(mpg~interaction(as.factor(ifelse(vs,"S","V")),as.factor(cyl))))
abline(v=c(2.5,4.5),col=8)
(Assuming I have "S" and "V" - for "straight" and "vee" engine configurations - the correct way to go if the R implementation matches the Hocking 1976 doc as described on the first page here - I think it should be right)
+2
source to share
You mean something like:
data(mtcars)
y <- mtcars$mpg
vs <- as.factor(mtcars$vs)
cyl <- as.factor(mtcars$cyl)
par(mfrow=c(1,2))
plot(formula = y ~ cyl + vs)
Likewise, you can use the package lattice
like this:
require(lattice)
bwplot( ~ y | vs + cyl)
Note: the only problem with this type of plot is that the result is essentially 6 plots in one (since for cyl there are 2 levels for vs * 3). Therefore, if you don't have enough data for every possible combination, the resulting plot may not look so good ...
+1
source to share