How to visualize 3D contingency matrix?

I have a data like this:

> table(A,B,C)
, , C = FALSE

       B
A       FALSE TRUE
  FALSE   177   42
  TRUE      6    8

, , C = TRUE

       B
A       FALSE TRUE
  FALSE     5   31
  TRUE      4   10

How can I plot this on a single graph, possibly without imposing any hierarchy?

Answer

I would try some kind of 3D heatmap, mosaic plot or a sieve plot (available in the vcd package). Isn’t the base mosaicplot() function working with three-way table? (at least mosaic3d() in the vcdExtra package should work, see e.g. http://datavis.ca/R/)

Here’s an example (including a conditional plot):

A <- sample(c(T,F), 100, replace=T)
B <- sample(c(T,F), 100, replace=T)
C <- sample(c(T,F), 100, replace=T)
tab <- table(A,B,C)
library(vcd)
sieve(tab, shade=TRUE)
cotabplot(tab)
library(vcdExtra)
mosaic3d(tab, type="expected", box=TRUE)

alt text

alt text

alt text

Actually, the rendering of mosaic3d() rely on the rgl package, so it is hard to give a pretty picture of the result.

Attribution
Source : Link , Question Author : Community , Answer Author : chl

Leave a Comment