高级格函数(Lattice Function)
多面板散点图
setwd("E:/R/R-beginer-guide/data/RBook")
Env <- read.table(file="RIKZENV.txt",header=TRUE)
Env$MyTime <- Env$Year+Env$dDay3/365 #生成一个代表时间天数的新变量
library(lattice) #载入
xyplot(SAL ~ MyTime | factor(Station),type="1",
strip = function(bg,...)
strip.default(bg='white',...),
col.line=1,data=Env) #SAL为y,MyTime为x,factor(Station)为条件变量,作用是生成多面板
strip函数表示对每一个带使用白色背景,col.line=1,对图形使用黑色的线条
其中例如type="r"为回归线,smooth为LOESS拟合,g为增加一个参考网格,l则是将点用线连起来,a是将每个面板中每组均值用线连起来
当使用连续变量时,会被默认为每个值都为离散值,因此需要将其分割为区间,函数single和equal.count可以完成该任务
参数strip需要包含一个F或T来说明是否绘制这个带状,以下是不同的命令绘制图有所区别:
xyplot(SAL ~ MyTime | factor(Station),data=Env)
xyplot(SAL ~ MyTime | factor(Station),type="1",strip=TRUE,col.line = 1,data=Env)
xyplot(SAL ~ MyTime | factor(Station),type="1",strip=FALSE,col.line = 1,data=Env)
多面板盒形图:bwplot
bwplot(SAL ~ factor(Month)|Area ,strip=strip.custom(bg='white'),
cex=0.5,layout=c(2,5),data=Env,xlab="Month",ylab="Salinity",
par.settings=list(
box.rectangle = list(col=1)