R tips/Contingency Tables
Plotting contingency data
Along with the convoluted bubble plot that we constructed in lab (QERM 598, Week 5), a student revealed several powerful visualizations of contingency data that R offers. These are: mosaicplot(table(Cat1,Cat2)) and assocplot(table(Cat1,Cat2)) where "Cat1" and "Cat2" are two categorical vectors that are tabulated in "contingency" format. These are very useful, easy functions for visualization!
The mosaic plot on the right is busy, but it shows a way to present three categorical counts simultaneously: Age of females (from 4 to 18 years along the x-axis), Rookery (darker to lighter boxes represent four rookeries, from southermost Chirpoev to northern most Antsiferov) and the real variable of interest: Birth/No Birth (thistle and yellow colors). The width of the boxes is proportional to the number of observations.
Births<-read.table("http://wiki.cbr.washington.edu/qerm/images/d/d3/SealionBirths.dat",header=T) attach(Births) mycolors <- c("yellow1","yellow2","yellow3","yellow4", "thistle1","thistle2","thistle3","thistle4") mosaicplot(table(Age,paste(Birth,Island)),col=mycolors,main="")
Eli 14:46, 16 May 2008 (PDT)