我们已经学了基本图形系统,ggplot2,lattice,到底用哪个,目前比较火的是ggplot,很多包也是基于这个包,但是画图万变不离其综,要好好学习基本图形元素。
补充练习
#airquality数据中的wind画一个直方图
library(lattice)
histogram(~Wind,data = airquality,col = "grey")
#创建一个Ozone~Wind的散点图,添加标题
xyplot(Ozone~Wind, data = airquality,
main = "Ozone&Wind",
cex = 2,
pch = 21,
fill = "red")
#添加图例,用Month更改绘图符号的颜色
xyplot(Ozone~Wind, data = airquality,groups = Month,
main = "Ozone&Wind",
cex = 2,
pch = 1,
auto.key = T)
#根据Month进行分区
xyplot(Ozone~Wind | factor(Month), data = airquality,groups = Month,
main = "Ozone&Wind",
cex = 2,
pch = 1,
auto.key = T)
#用面板函数添加一个线性回归线
myPanel <- function(x,y,...){
myLm <- lm(y~x)
panel.abline(myLm,col = "red")
panel.xyplot(x,y,...)
}
xyplot(Ozone~Wind | factor(Month), data = airquality,groups = Month,panel = myPanel,
main = "Ozone&Wind",
cex = 2,
pch = 1,
auto.key = T)
就挑一个来一学到底吧,ggplot2.