if (FALSE) {
require(PairViz)
tab <- apply(HairEyeColor, c(1, 2), sum)
dev.new()
par(mar=c(3,3,1,1))
par(cex=.6,mgp=c(2, -.5, 0))
table_plot(sqrt(tab),sqrt(tab))
# this table plot has cells with widths and heights proportional to the square root of cell counts.
tabp <- prop.table(tab,2)
table_plot(apply(tab,2,sum),tabp) # make cell widths proportional to
#margin totals, heights to conditional prob
cols <- 2:5
table_plot(apply(tab,2,sum),tabp, yjust="bottom",col=cols,yruler=c("left","right"))
# add colours, rulers and bottom-justify
# The result is similar to the mosaic, without the mosaic effect of equalizing gaps.
#In the table version the rectangles line up across rows,
#so comparing heights, ie. conditional probs is easier.
o <- hpaths(1:4)[2,]
table_plot(apply(tab,2,sum)[o],tabp[,o], yjust="bottom",col=cols,yruler=c("left","right"))
# Permutes the columns so all pairs of columns can be compared.
#In the second permutation can easily see that
#p(black|blue eyes)> p(black|green eyes)
dev.new()
par(mar=c(3,3,1,1))
par(mgp=c(2, -.5, 0))
mosaicplot(t(tab)[,nrow(tab):1],col=rev(cols),main="")
# mosaic- good for seeing deviations from independence. hard to compare conditional probs,
# except for those in the bottom and top rows.
}
Run the code above in your browser using DataLab