I have this data set:
x <- sample(80)
matrix <- matrix(x, ncol=5, nrow=16)
matrix <- cbind(matrix, c(rep("group1",4), rep("group2",4), rep("group3",4), rep("group4",4)))
colnames(matrix) <- c(letters[1:5], "groups")
df <- as.data.frame(matrix)
I would like to be able to plot five boxplots, one for each column from a to e, using a for loop. I have tried this, but I cannot figure out how to make it work:
for(i in df[,1:5]) {
p <- ggplot(df, aes(x=groups, y=as.numeric(as.character(i))))
p + geom_boxplot()
}