[R] Gray level mosaic plot with shading_Friendly

Michael Friendly friendly at yorku.ca
Wed Jul 7 05:35:09 CEST 2010


Michael Kubovy wrote:
> Suppose we start with
> 
> data("Titanic")
> mosaic(Titanic, shade = TRUE)
> 
> How do I combine the dashed box contours of shading_Friendly to indicate negative residuals, with three levels of gray: dark for abs(Pearson Resid) > 4, lighter for 4 > abs(Pearson Resid) > 2, and lightest for bs(Pearson Resid) < 2 ?
> 

Do you mean [1] you want to plot positive residuals in color and 
negative in    gray scale?
Or [2] to fold + and - residuals by shading all according to abs(resid), and
distinguishing + from - by the dashed box outlines?

In fact, I designed this coding scheme so that mosaic plots in color 
(with my blue - white - red scheme) would approximately do exactly what
you might want under [2], when rendered in B/W, since the fully 
saturated red and blue are close in  darkness in B/W.

Try
mosaic(Titanic, gp=shading_Friendly)
save as a jpg/png and try converting to B/W with an image program and 
see if this is good enough.

Alternatively, write your own, shading_Kubovy, modeled on

shading_Friendly <-
function (observed = NULL, residuals = NULL, expected = NULL,
     df = NULL, h = c(2/3, 0), lty = 1:2, interpolate = c(2, 4),
     eps = 0.01, line_col = "black", ...)
{
     shading_hsv(observed = NULL, residuals = NULL, expected = NULL,
         df = NULL, h = h, v = 1, lty = lty, interpolate = interpolate,
         eps = eps, line_col = line_col, p.value = NA, ...)
}
<environment: namespace:vcd>
attr(,"class")
[1] "grapcon_generator"

In the defaults, lty=1:2 is what distinguishes + and - for outline line type

hope this helps,
-Michael



More information about the R-help mailing list