[R] plain shading (not residuals) in mosaic plot

From: Kie Zuraw <kie_at_ucla.edu>
Date: Thu 20 Jul 2006 - 00:47:32 EST

Hello. I've been using R for a couple of months and enjoying it a lot. This is my first post to R-help.

I'm using the vcd package to make mosaic plots with labels on the tiles indicating the number of items in each cell.

For example, I've made this plot:

> allmorph<-structure(c(10, 26, 17, 100, 70, 97, 253, 430, 185, 177,
> 25, 1), .Dim = as.integer(c(6, 2)), .Dimnames =
> structure(list(Stem.initial.obstruent = c("p", "t,s",
> "k","b","d","g"),Subst.behavior=c("unsubstituted","substituted")),
> .Names = c("Stem-initial obstruent","Behavior according to
> dictionary")), class = "table")
> mosaic(allmorph,direction="v",pop=FALSE)
> labeling_cells(text=allmorphs,margin=0)(allmorph)

So far so good. What I can't figure out how to do--after searching through the vcd documentation
http://cran.r-project.org/doc/packages/vcd.pdf), Googling, and checking the r-help archive--is how to shade the tiles according to their values for the variables rather than to reflect residuals. That is, I want all the tiles at the bottom, whose value for the x-axis variable is "substituted", to be dark grey, and those at the top, in the "unsubstituted" category, to be light grey.

I know how to do it with mosaicplot():

> mosaicplot(morphs3,color=c(grey(0.8),grey(0.4)))

...but this doesn't work with mosaic(): the command "mosaic(morphs3,color=c(grey(0.8),grey(0.4)))" yields a plot with all tiles the same color. And conversely, I can't find a way to use mosaicplot() and add numeric labels to the tiles--without much hope of success, I tried combining mosaicplot() with labeling_cells(), but, unsurprisingly, it didn't work:

> mosaicplot(morphs3,color=c(grey(0.8),grey(0.4)),pop=FALSE)
Warning message:
extra argument(s) 'pop' will be disregarded in: mosaicplot.default(morphs3, color = c(grey(0.8), grey(0.4)),
> labeling_cells(text=morphs3,margin=0)(morphs3)
Error in downViewport.vpPath(vpPathDirect(name), strict, recording = recording) : Viewport 'cell:Stem-initial obstruent=p,Behavior according to dictionary=unsubstituted' was not found

Does anyone know how to get both the shading I want and the labels I want, whether with mosaic(), with mosaicplot(), or in some other way?

Thanks for your attention.

-Kie Zuraw

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu Jul 20 00:52:18 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 20 Jul 2006 - 06:16:20 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.