箱线图

  • 箱线图
通过绘制连续型变量的最小值,下四分位数(25%位数)、中位数(50%分位数)、上四分位数(75%分位数)以及最大值,描述连续性变量的分布,箱线图能够显示出可能的离群点(范围+-1.5*IQR以外的值,IQR表示四分位距,即上分位数与下四分位数的差值)的观测值
boxplot(mtcars$mpg,main="Box plot",ylab="Miles per Gallon")
boxplot.stats(mtcars$mpg)  #查看统计量,最小值、下分位,中位数,上分位,最大值
boxplot(mtcars$mpg,main="Box plot",ylab="Miles per Gallon")
x
1
boxplot(mtcars$mpg,main="Box plot",ylab="Miles per Gallon")
2
boxplot.stats(mtcars$mpg)  #查看统计量,最小值、下分位,中位数,上分位,最大值

  • 使用并列箱线图进行跨组比较
箱线图可以展示单个变量或分组变量,使用格式为:
boxplot(formula,data = dataframe)
1
1
 
1
boxplot(formula,data = dataframe)
formula:是一个公式,y ~ A 这将为类别变量 A 的每个值并列生成数值型变量 y 的箱线图
                                     y ~A*B则将为类别型变量 A 和 B所有水平的两两组合生成数值型变量 y 的箱线图 (两个交叉因子的箱线图)
dataframe:代表提供数据的数据框或者列表 
varwidth: 为TRUE将使箱线图的宽度与其样本大小的平方根成正比
horizontal:为TRUE可以反转坐标轴的方向
notch:为TRUE可以得到凹槽的箱线图,若两个凹槽互不重叠,则表明它们中位数有显著差异

boxplot(mpg~cyl,data=mtcars,
        main="Car Milage Data", 
        xlab="Number of Cylinders", 
        ylab="Miles Per Gallon")
4
4
 
1
boxplot(mpg~cyl,data=mtcars,
2
        main="Car Milage Data", 
3
        xlab="Number of Cylinders", 
4
        ylab="Miles Per Gallon")
06113738_gUAf.png
#含凹槽的箱线图
boxplot(mpg~cyl,data=mtcars, 
        notch=TRUE, 
        varwidth=TRUE,
        col="red",
        main="Car Mileage Data", 
        xlab="Number of Cylinders", 
        ylab="Miles Per Gallon")
8
8
 
1
#含凹槽的箱线图
2
boxplot(mpg~cyl,data=mtcars, 
3
        notch=TRUE, 
4
        varwidth=TRUE,
5
        col="red",
6
        main="Car Mileage Data", 
7
        xlab="Number of Cylinders", 
8
        ylab="Miles Per Gallon")
06113738_Pptf.png
 
#两个交叉因子的箱线图
boxplot(mpg ~ am.f *cyl.f, 
        data=mtcars, 
        varwidth=TRUE,
        col=c("gold", "darkgreen"),
        main="MPG Distribution by Auto Type", 
        xlab="Auto Type")
7
 
1
#两个交叉因子的箱线图
2
boxplot(mpg ~ am.f *cyl.f, 
3
        data=mtcars, 
4
        varwidth=TRUE,
5
        col=c("gold", "darkgreen"),
6
        main="MPG Distribution by Auto Type", 
7
        xlab="Auto Type")
06113739_xoED.png
 


转载于:https://my.oschina.net/u/1785519/blog/1563080

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值