2017-05-20 16:29:52
类似于S-Plus中的Trellis,调用grid作图系统产生Trellis对象
xyplot: 散点图、折线图barchart: 柱图bwplot: box-and-whiskers plots (箱式图)histogram: 直方图densityplot: 密度曲线图stripplot: 散点密度图dotplot: 琴弦散点密度图splom: 类似于pairs,散点图矩阵levelplot, contourplot: 像素图<作图函数名>(x, data, ...)
y ~ x | g1 * g2 * ... 或 y ~ x | g1 + g2 + ...连续型变量的关联
library(lattice) xyplot(mpg~wt, data=mtcars)

文本型变量也可以用于绘制散点图
xyplot(decrease~treatment, data=OrchardSprays)

单变量密度分布
histogram(~mpg, data=mtcars)

或用密度曲线图
densityplot(~mpg, data=mtcars)

连续性变量的分布
bwplot(~len, ToothGrowth)

多个箱式图
bwplot(len~dose, data = ToothGrowth,
horizontal=FALSE)

stripplot和bwplot功能相近
stripplot(len~dose, data = ToothGrowth,
horizontal=FALSE)

dotplot把点画在琴弦上
dotplot(len~dose, data = ToothGrowth,
horizontal=FALSE)

文本型变量为y,条图
hp <- data.frame(hp=mtcars$hp,
car=row.names(mtcars))
barchart(car~hp, data=hp)

颠倒x和y,柱形图
hp <- data.frame(hp=mtcars$hp,
car=row.names(mtcars))
barchart(hp~car, data=hp)

表示趋势
xyplot(AirPassengers, type="l")

# type类似于base系统
阶梯折线
xyplot(AirPassengers, type='s') # 阶梯图

splom(~iris[1:4], groups=Species, data=iris,
main = "Anderson's Iris Data -- 3 species")

Parallel特别适合展示高维数据
parallelplot(~iris[1:4] | Species, data=iris)

多重面板图是lattice最大的利器
xyplot(Sepal.Width ~ Petal.Width | Species,
data=iris)

xyplot(mpg ~ wt | am * vs, data=mtcars)

## 交叉am和vs
下图显示,气温越高、风速越小,则臭氧浓度越高(映射到色阶通道)。
levelplot(Ozone ~ Wind * Temp, data=airquality)

cloud(Ozone ~ Wind * Temp, data=airquality)

library(latticeExtra) cloud(Ozone ~ Wind * Temp, data=airquality, panel.3d.cloud=panel.3dbars)

Thank you!