1 多面板散点图:xyplot
载入数据:
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) 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)2 多面板盒型图: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), box.umbrella = list(col = 1), box.symbol = list(cex = 0.5,col =1) ))3 多面板克里夫兰点图:
dotplot(factor(Month)~SAL|Station, subset= Area=="OS",jitter.x=TRUE, col=1,data=Env,strip=strip.custom(bg='white'), cex=0.5,ylab="Month",xlab="Salinity")4 多面板直方图:histogra
histogram(~ SAL|Station,data=Env, subset=(Area == "OS"),layout=c(1,4), nint=30,xlab="Salinity",ylab="Frequencies", strip=FALSE,strip.left=TRUE )5面板函数
5.1
xyplot(SAL~Month|Year,data=Env, type=c("p"),subset=(Station=="GROO"), xlim=c(0,12),ylim=c(0,30),pch=19, panel=function(...){ panel.xyplot(...) panel.grid(...,h=-1,v=-1) panel.loess(...) })
5.2
dotplot(factor(Month)~SAL|Station,pch=16, subset=(Area=="OS"),data=Env, ylab="Month",xlab="Salinity", panel=function(x,y,...){ Q<- quantile(x,c(0.25,0.5,0.75),na.rm=TRUE) R<- Q[3]-Q[1] L<- Q[2]-3*(Q[3]-Q[1]) MyCex <- rep(0.4,length(y)) MyCol<- rep(1,length(x)) MyCex[x<L]<-1.5 MyCol[x<L]<-2 panel.dotplot(x,y,cex=MyCex,col=MyCol,...) })5.3
setwd("E:/R/R-beginer-guide/data/RBook") Sparrows <- read.table(file="Sparrows.txt",header=TRUE) xyplot(Wingcrd~Tarsus|Species*Sex, xlab="Axis 1",ylab="Axis 2",data=Sparrows, xlim=c(-1.1,1.1),ylim=c(-1.1,1.1), panel=function(subscripts,...){ zi <- Sparrows[subscripts,3:8] di <- princomp(zi,cor=TRUE) Load <- di$loadings[,1:2] Scor <- di$scores[,1:2] panel.abline(a=0,b=0,lty=0,col=1) panel.abline(h=0,v=0,lty=2,col=1) for(i in 1:6){ llines(c(0,Load[i,1]),c(0,Load[i,2]),col=1,lwd=2) ltext(Load[i,1],Load[i,2],rownames(Load)[i],cex=0.7) } sc.max<-max(abs(Scor)) Scor <- Scor/sc.max panel.points(Scor[,1],Scor[,2],pch=1,cex=0.5,col=1) })