[R] Contingency tables profiles

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Fri Feb 18 17:27:15 CET 2005


On Fri, 18 Feb 2005 10:50:37 -0500 Campo Elías PARDO wrote:

> Thank for your help
> 
> I obtained profiles and I found mosaicplot as an interesting
> alternative.
> 
> I don't like my solution about legend in profiles graphics: I inserted
> empty extra columns in order to avoid tue superimposed of legend.
> 
> #Data
> N <- matrix(0,3,6)
> N[1,] <- c(7,7,5,0,4,4)
> N[2,] <- c(0,0,0,5,5,5)
> N[3,] <- c(4,4,0,0,3,0)
> rownames(N) <- c("Ple1","Ple2","Ple3")
> colnames(N) <- c("A","B","C","D","E","F")
> N
> # Row profiles
> PF <- N/rowSums(N)

This could also be done by
  prop.table(N, 1)

> # Columns profiles
> PC <- t(N)/rowSums(t(N))

and this by
  prop.table(N, 2)

> # Graphics
> par(mfrow=c(2,2))
> barplot(cbind(cbind(t(PF),0),0),legend=colnames(F),density=100,cex.na

Note, that you could also do
  cbind(t(PF), 0, 0)

Instead of adding 0s, you could also set xlim.

> mes=0.8)
> barplot(cbind(cbind(cbind(t(PC),0),0),0),legend=rownames(F),density=1
> 00,cex.names=0.8)
> mosaicplot(N,color=TRUE)

Note that the mosaicplot is very similar to the stacked barplot (in fact
it is a generalization of stacked barplots).

R> mosaicplot(N, color = TRUE)

gives you the distribution of A-F conditional on Ple1-3, but it also
visualizes the marginal distribution of Ple1-3. If you should want to
ignore the latter, you could do

R> mosaicplot(prop.table(N, 1), color = TRUE)

and the latter is essentially equivalent to your barplot

R> barplot(t(PF), legend = TRUE, xlim = c(0.2, 4))

And, vice versa, if you want to visualize the conditional distribution
of Ple1-3 given A-F, you can do.

R> mosaicplot(t(N), color = TRUE)
R> mosaicplot(t(prop.table(N, 2)), color = TRUE)

hth,
Z

> library(ade4)
> table.cont(t(N),csize=4.5,col.labels=rownames(N))
> 
> 
> 
> Campo Elías  PARDO
> cepardot at cable.net.co
> cepardot at unal.edu.co 
>




More information about the R-help mailing list