箱式图
箱线图(又称盒须图)通过绘制连续型变量的五数总括,即最小值、下四分位数(第25百分位数)、中位数(第50百分位数)、上四分位数(第75百分位数)以及最大值,描述了连续型变量的分布。箱线图能够显示出可能为离群点(范围±1.5*IQR以外的值,IQR表示四分位距,即上四分位数与下四分位数的差值)的观测。
boxplot(mtcars$mpg, main="Box plot", ylab="Miles per Gallon")
Rplot28.jpeg
并列箱线图
boxplot(mpg ~ cyl, data=mtcars, main="Car Mileage Data",
xlab="Number of Cylinders",ylab="Miles Per Gallon")
Rplot29.jpeg
对box图的参数进行修改
boxplot(mpg ~ cyl, data=mtcars,notch=TRUE,varwidth=TRUE,
col=c("gold","darkgreen","red"),main="Car Mileage Data",
xlab="Number of Cylinders",ylab="Miles Per Gallon")
Rplot30.jpeg
双因素交叉的箱式图
mtcars$cyl.f <- factor(mtcars$cyl,levels=c(4,6,8),labels=c("4","6","8"))
mtcars$am.f <- factor(mtcars$am,levels=c(0,1),labels=c("auto", "standard"))
boxplot(mpg ~ am.f *cyl.f,data=mtcars,varwidth=TRUE, col=c("gold","darkgreen"),
main="MPG Distribution by Auto Type",
xlab="Auto Type", ylab="Miles Per Gallon")
Rplot31.jpeg