# Trellis Examples library(lattice) attach(mtcars) names(mtcars) # create factors with value labels gear.f<-factor(gear,levels=c(3,4,5),labels=c("3gears","4gears","5gears")) cyl.f <-factor(cyl,levels=c(4,6,8),labels=c("4cyl","6cyl","8cyl")) # kernal density plot densityplot(~mpg,main="Density Plot",xlab="Miles per Gallon") # kernal density plots by factor level densityplot(~mpg|cyl.f,main="Density Plot by Number of Cylinders",xlab="Miles per Gallon") # kernal density plots by factor level (alternate layout) densityplot(~mpg|cyl.f,main="Density Plot by Numer of Cylinders",xlab="Miles per Gallon",layout=c(1,3)) # boxplots for each combination of two factors bwplot(cyl.f~mpg|gear.f, ylab="Cylinders", xlab="Miles per Gallon",main="Mileage by Cylinders and Gears",layout=(c(1,3))) # scatterplots for each combination of two factors xyplot(mpg~wt|cyl.f*gear.f,main="Scatterplots by Cylinders and Gears",ylab="Miles per Gallon", xlab="Car Weight") # 3d scatterplot by factor level cloud(mpg~wt*qsec|cyl.f,main="3D Scatterplot by Cylinders") #3d wireframe x <- seq(-pi, pi, len = 20) y <- seq(-pi, pi, len = 20) g <- expand.grid(x = x, y = y) g$z <- sin(sqrt(g$x^2 + g$y^2)) wireframe(z ~ x * y, g, drape = TRUE, aspect = c(3,1), colorkey = TRUE,main=expression(paste(z==sin(sqrt(x^2+y^2)))))