# Lattice graphics #----------------- library(faraway) library(lattice) str(nels88) summary(nels88) xtabs(~paredu, data=nels88) # Graphing counts and percents histogram(~ paredu, data=nels88) # basic histogram(~ paredu, data=nels88, type="count") #rescaled histogram(~ math, data=nels88, type="count") # auto-binned nt <- length(xtabs(~math, data=nels88)) histogram(~ math, data=nels88, type="count", nint=nt) barchart(~ table(math), data=nels88) # chart the table, not the variable densityplot(~ math, data=nels88) with(nels88, hist(math)) # the graphics-package version # Crosstabs histogram(~math | race, data=nels88) densityplot(~math | race, data=nels88) histogram(~paredu | race, data=nels88) # T-test bwplot(math~sex, data=nels88) # Extending the comparison, ala lm() bwplot(math~sex | race, data=nels88) bwplot(math~sex | race*paredu, data=nels88) dotplot(math~sex | race*paredu, data=nels88) # F-test bwplot(math~race, data=nels88) bwplot(math~race | paredu, data=nels88) # Correlation xyplot(math ~ ses, data=nels88) xyplot(math ~ ses, data=nels88, panel=function(x, y){ panel.xyplot(x, y) panel.lmline(x, y) }) xyplot(math ~ ses | race, data=nels88, panel=function(x, y){ panel.xyplot(x, y) panel.lmline(x, y) }) mathplot <- xyplot(math ~ ses | paredu, data=nels88, panel=function(x, y){ panel.xyplot(x, y) panel.lmline(x, y) }) plot(mathplot) str(mathplot) mathplot <- update(mathplot, main="Math Score v SES by Paredu") print(mathplot) xyplot(math ~ ses | paredu, groups=race, data=nels88, auto.key=TRUE) # d <- matrix(rnorm(15000, mean=7.5, sd=5), nrow=15) samplemeans <- colMeans(d) dp <- densityplot(as.vector(d)) plot(dp) str(dp) sp <- densityplot(samplemeans, plot.points=FALSE) plot(sp) sp1<- update(sp, xlim=dp$x.limits) plot(sp1)