Alex Rivera | Logout

R: Plot multiple box plots using columns from data frame

Asked 2012-07-05T14:52:31.487
21

I would like to plot an INDIVIDUAL box plot for each unrelated column in a data frame. I thought I was on the right track with boxplot.matrix from the sfsmsic package, but it seems to do the same as boxplot(as.matrix(plotdata) which is to plot everything in a shared boxplot with a shared scale on the axis. I want (say) 5 individual plots.

I could do this by hand like:

par(mfrow=c(2,2))
boxplot(data$var1
boxplot(data$var2)
boxplot(data$var3)
boxplot(data$var4)

But there must be a way to use the data frame columns?

EDIT: I used iterations, see my answer.

Edit
Report

1 Answer

6

I used iteration to do this. I think perhaps I wasn't clear in the original question. Thanks for the responses none the less.

par(mfrow=c(2,5))
for (i in 1:length(plotdata)) {
        boxplot(plotdata[,i], main=names(plotdata[i]), type="l")

}
answered 2012-07-06T08:58:04.000

Your Answer