一、箱型图
1. 箱型图
air<-read.csv("airpollution.csv")
boxplot(air,las=1) #las指定坐标轴刻度的风格,1表示水平放置
2. 收窄箱体宽度
boxplot(air,boxwex=0.2,las=1) #boxwex设置箱体收窄比例,但这里的0.2并不表示收窄到原来的0.2倍
3. 指定箱体的宽度
boxplot(air,width=c(1,2)) #width指定两个箱体的宽度,分别为1和2
4. 分组
metals<-read.csv("metals.csv")
boxplot(Cu~Source, #纵轴是Cu,横轴是Source
data=metals,
main="Summary of Copper (Cu) concentrations by Site")
boxplot(Cu~Source*Expt, #根据Source与Expt所有可能的不同组合值来分组
data=metals,
main="Summary of Copper (Cu) concentrations by Site")
5. 观测值数量决定箱体宽度
boxplot(Cu ~ Source,
data = metals,
varwidth=TRUE, #varwidt如果TRUE,则箱体宽度由观测值数目决定
main="Summary of Copper concentrations by Site")
6. 带notch(切口) 的箱型图
boxplot(Cu ~ Source,
data = metals,
varwidth=TRUE,
notch=TRUE, #notch如果TRUE,则箱型图是带切口的
main="Summary of Copper concentrations by Site")
7. 排除离群值
boxplot(metals[,-1],
outline=FALSE, #outline如果FALSE,则排除离群值。默认为TRUE
main="Summary of metal concentrations by Site (without outliers)")
8. 水平放置
boxplot(metals[,-1],
horizontal=TRUE, #箱型图水平放置
las=1,
main="Summary of metal concentrations by Site")
9. 改变箱型风格
boxplot(metals[,-1],
border = "white", #箱体边框颜色
col = "black", #箱体颜色
boxwex = 0.3, #箱体宽度
medlwd=1, #中位数线的宽度
whiskcol="black", #触须的颜色
staplecol="black", #两个横杆的颜色
outcol="red", #离群值的颜色
cex=0.3, #离群值点符号的大小
outpch=