How to create one box plot using multiple columns and argument “split”

放肆的年华 提交于 2019-12-03 09:01:21

Try putting your data into long form first and then plotting:

temp = reshape(data, direction="long", varying=2:4, sep="")
boxplot(split(temp[,3], temp[,1]))
# boxplot(car ~ paint, data=temp) ### Formula notation, easier to read

Or, use lattice:

library(lattice)
bwplot(car1 + car2 + car3 ~ paint, data=data)

I'm not sure why that notation doesn't work with base R's boxplot though.

Update

In case I misinterpreted your original question (after reading Roman's comment), here's an option (again using lattice) that puts boxplots for car1, car2, and car3 separately but side-by-side. This uses the long-form data temp created in the first example:

bwplot(car ~ paint | paste0("Car ", time), data = temp)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!