慕课R语言之数据可视化学习笔记——3.3基本绘图系统实战
2016-05-22 15:48
357 查看
1.1 HIST
hist用于绘制直方图,使用内置的airquality数据为案例:
hist(airquality$Temp)#绘制airquality中的温度Temp直方图。
结果:
2 boxplot
绘制箱图函数
code:
boxplot(airquality$Wind,xlab="wind",ylab="speed")#绘制
可以看到存在极端值。
3并排箱图
对于不同月份下的风速,使用并排箱图可以观察数值变换
例如
boxplot(Wind~Month,airquality,xlab="month",ylab="speed")
with函数
使用with函数,可以将数据集进行绑定
with(airquality,plot(Wind,Temp,title(main = "wind and temp")))
#使用plot函数时,表示使用的是airquality中的数值。
#散点图如下
4:%in%
用来获得特定情况的数值
with(subset(airquality,Month %in% c(6,7,8)), points(Wind,Temp,col="green"))
5线性拟合
在图像中添加拟合直线
fit=lm(Temp~Wind,airquality)
abline(fit,lwd=2)#add line to the pic
6 添加标注
topright 为右上角的位置添加legend
legend("topright",pch=1,col=c("red","blue","black"
),
legend=c("SEp","May","other"))
hist用于绘制直方图,使用内置的airquality数据为案例:
hist(airquality$Temp)#绘制airquality中的温度Temp直方图。
结果:
2 boxplot
绘制箱图函数
code:
boxplot(airquality$Wind,xlab="wind",ylab="speed")#绘制
可以看到存在极端值。
3并排箱图
对于不同月份下的风速,使用并排箱图可以观察数值变换
例如
boxplot(Wind~Month,airquality,xlab="month",ylab="speed")
with函数
使用with函数,可以将数据集进行绑定
with(airquality,plot(Wind,Temp,title(main = "wind and temp")))
#使用plot函数时,表示使用的是airquality中的数值。
#散点图如下
4:%in%
用来获得特定情况的数值
with(subset(airquality,Month %in% c(6,7,8)), points(Wind,Temp,col="green"))
5线性拟合
在图像中添加拟合直线
fit=lm(Temp~Wind,airquality)
abline(fit,lwd=2)#add line to the pic
6 添加标注
topright 为右上角的位置添加legend
legend("topright",pch=1,col=c("red","blue","black"
),
legend=c("SEp","May","other"))