热线电话:13121318867

登录
2018-10-22 阅读量: 1112
怎么用R来画箱线图,这几个步骤就行了

箱线图函数:boxplot(x, ...)

## S3 method for class 'formula'

boxplot(formula, data = NULL, ..., subset, na.action = NULL)

## Default S3 method:

boxplot(x, ..., range = 1.5, width = NULL, varwidth = FALSE,        notch = FALSE, outline = TRUE, names, plot = TRUE,        border = par("fg"), col = NULL, log = "",        pars = list(boxwex = 0.8, staplewex = 0.5, outwex = 0.5),        horizontal = FALSE, add = FALSE, at = NULL)

参数说明及示例解释:1、formula:一个公式,形式为y~A(类别型变量A的每个值并列地生成数值型变量y的箱线图)或y~A*B

par(mfrow=c(1,2))

boxplot(mpg~cyl,data = mtcars,main="car mileage data",xlab="number of cylinders", ylab="miles per gallon")

boxplot(mpg~cyl*am,data = mtcars,main="car mileage data",xlab="number of cylinders")

2、varwidth:取值TRUE,绘制的箱线图的宽度与其样本大小的平方根成正比。

代码及图形:

par(mfrow=c(1,2))

boxplot(mpg~cyl,data = mtcars,main="car mileage data",xlab="number of cylinders",

        ylab="miles per gallon")

boxplot(mpg~cyl,data = mtcars,varwidth=TRUE,

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

3、width:绘制每个箱线图的相对宽度,取值向量;

par(mfrow=c(1,2))

boxplot(mpg~cyl,data = mtcars,main="car mileage data",xlab="number of cylinders",

        ylab="miles per gallon")

boxplot(mpg~cyl,data = mtcars,width=c(1,2,3),

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

4、notch:取值true,可绘制含凹槽的箱线图;

par(mfrow=c(1,2))

boxplot(mpg~cyl,data = mtcars,main="car mileage data",xlab="number of cylinders",

        ylab="miles per gallon")

boxplot(mpg~cyl,data = mtcars,notch=TRUE,

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

5、outline:默认取值TRUE,绘制离群值。如取值FALSE,不绘制离群值;

par(mfrow=c(1,2))

boxplot(mpg~cyl,data = mtcars,notch=TRUE,

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

boxplot(mpg~cyl,data = mtcars,notch=TRUE,outline=FALSE,

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

6、names:每个箱线图下的组标签;

par(mfrow=c(1,2))

boxplot(mpg~cyl,data = mtcars,

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

boxplot(mpg~cyl,data = mtcars,names=c(1,2,3),

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

7、boxwex:取值向量,控制箱线图的宽度。par(mfrow=c(1,2))

boxplot(mpg~cyl,data = mtcars,

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

boxplot(mpg~cyl,data = mtcars,boxwex=c(0.5,1,1.5),

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

8、staplewex:最小值、最大值对应的钉线宽度的调整,取值向量;

par(mfrow=c(1,2))

boxplot(mpg~cyl,data = mtcars,

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

boxplot(mpg~cyl,data = mtcars,staplewex=c(0.5,1,1.5),

        main="car mileage data",xlab="number of cylinders",ylab="miles per gallon")

9、outwex:取值向量。离群线宽度扩展,扩展比例与盒宽成正比。

0.0000
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子