[R] Gray level mosaic plot with shading_Friendly

Achim Zeileis Achim.Zeileis at uibk.ac.at
Wed Jul 7 18:20:07 CEST 2010



On Wed, 7 Jul 2010, Michael Kubovy wrote:

> Dear Achim and Michael,
>
> Thank you so much. Indeed, mosaic(Titanic, gp = shading_hcl, gp_args = 
> list(lty = 1:2, c = 0)) does almost what I was looking for, except that 
> for consistency and clarity, I would have expected the negative values 
> on the legend to be be outlined with lty = 2.

In the continuous legend, that is employed by default (legend_resbased), 
it is visually not very compelling to show line types as well. But you can 
set legend = legend_fixed which displays this information (but is less 
intuitive concerning the interval ranges).

Best,
Z

> Michael
>
>
> On Jul 7, 2010, at 2:13 AM, Achim Zeileis wrote:
>
>> On Tue, 6 Jul 2010, Michael Friendly wrote:
>>
>>> 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.
>>
>> And shading_hcl() has been written to do exactly what you want under [2]. While it is hard to come up with colors of different hues in HSV or HLS space that have the same brightness (aka lightness/luminance) and the same
>> colorfulness (aka chroma), this is easy in HCL.
>>
>>> 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.
>>
>> mosaic(Titanic, shade = TRUE)
>>
>> is the same as
>>
>> mosaic(Titanic, gp = shading_hcl)
>>
>> which you can then modify to have different line types
>>
>> mosaic(Titanic, gp = shading_hcl, gp_args = list(lty = 1:2))
>>
>> If you print that on a grayscale printer you will see the same plot without any chroma, i.e.,
>>
>> mosaic(Titanic, gp = shading_hcl, gp_args = list(lty = 1:2, c = 0))
>>
>> The shading_hcl() function is introduced in Zeileis et al. (2007, JCGS), see ?shading_hcl, which provides more detailed references to HCL colors etc.
>>
>> Best,
>> Z
>>
>>> 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
>>>
>>> ______________________________________________
>>> R-help at r-project.org 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.
>>>
>
>



More information about the R-help mailing list