lattice包提供了用于可视化单变量和多变量数据的一整套图形系统。许多用户转向使用lattice包是因为它能很容易地生成网格图形。网格图形能够展示变量的分布或变量之间的关系。
例:
data(mtcars)
attach(mtcars)
# Create factors with value labels
gear <- factor(gear, levels=c(3, 4, 5),
labels=c("3 gears", "4 gears", "5 gears"))
cyl <- factor(cyl, levels=c(4, 6, 8),
labels=c("4 cylinders", "6 cylinders", "8 cylinders"))
# Generate plots
densityplot(~ mpg,
main="Density Plot",
xlab="Miles per Gallon")
densityplot(~ mpg | cyl,
main="Density Plot by Number of Cylinders",
xlab="Miles per Gallon")
bwplot(cyl ~ mpg | gear,
main="Box Plots by Cylinders and Gears",
xlab="Miles per Gallon", ylab="Cylinders")
xyplot(mpg ~ wt | cyl * gear,
main="Scatter Plots by Cylinders and Gears",
xlab="Car Weight", ylab="Miles per Gallon")
cloud(mpg ~ wt * qsec | cyl,
main="3D Scatter Plots by Cylinders")
dotplot(cyl ~ mpg | gear,
main="Dot Plots by Number of Gears and Cylinders",
xlab="Miles Per Gallon")
splom(mtcars[c(1, 3, 4, 5, 6)],
main="Scatter Plot Matrix for mtcars Data")
detach(mtcars)
图形较多不一一展示
更多请看《R语言实战》(第二版)第23章