第12周课程:箱型图,热力图

本文详细介绍了如何绘制箱型图和热力图。首先讲解了箱型图的基本概念,包括如何收窄箱体宽度,并推荐使用gplot包进行绘制。接着,文章提到了函数化编程的优势,可以避免重复工作,提高效率。随后,文章转向热力图的制作,为读者提供相关知识。
摘要由CSDN通过智能技术生成

一、箱型图

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=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值