I was wondering if it is possible to create a set of boxes similar to the one obtained from these combinations of nested loops using the apply function.
It may not be possible / necessary, but I thought it was possible, I just can’t wrap my head around how to do it.
I need to be able to build this to see how 100s of factors are compared in a single variable ( mtcars$mpg)
head(mtcars)
for (i in 8:11) {
for (j in 8:11) {
if (i != j) {
title = paste(names(mtcars)[i], names(mtcars)[j],
sep = "/")
p <- ggplot(mtcars, aes(interaction(mtcars[,i], mtcars[, j]), mpg, fill = factor(mtcars[,i]))) + geom_boxplot(alpha = I(0.7))
p <- p + ggtitle(title) + scale_fill_hue()
} else {
title = paste(names(mtcars)[i])
p <- ggplot(mtcars, aes(factor(mtcars[,i]), mpg, fill = factor(mtcars[, i]))) + geom_boxplot(alpha = I(0.7))
p <- p + ggtitle(title) + scale_fill_hue()
}
print(p)
}
}
source
share