On 04/04/2010 06:21, Deepayan Sarkar wrote:
> On Thu, Apr 1, 2010 at 4:10 AM, Luigi Ponti <[email protected]> wrote:
>
>> Hello,
>>
>> I am trying to give different colors to boxes in a violin plot obtained via
>> bwplot from lattice package using a color palette from RColorBrewer:
>> [...]
>> However, when I do the same thing with a violin plot from the lattice
>> package
>>
>>> require(lattice)
>>> bwplot(count ~ spray, data = InsectSprays,
>>>
>> + panel = function(..., box.ratio) {
>> + panel.violin(..., col = "transparent",
>> + varwidth = FALSE, box.ratio = box.ratio)
>> + panel.bwplot(..., fill = MyPalette, box.ratio = .1)
>> + } )
>>
>> boxplots are colored with the right colors (each box has a different color)
>> but with a different color order -- too bad because I would like to color
>> code the plot according to certain pre-defined colors. Same thing (wrong
>> color order) with a simple bwplot:
>>
>>
>>> bwplot(count ~ spray, data = InsectSprays, fill = MyPalette)
>>>
>> Is there a way to get the right color (i.e. same order as in MyPalette) in
>> bwplot/panel.violin?
>>
>
> The correct approach would be along the lines of
>
> bwplot(count ~ spray, data = InsectSprays,
> groups = spray,
> panel = panel.superpose,
> panel.groups = panel.violin,
> col = MyPalette)
>
> (unlike panel.xyplot etc., panel.bwplot does not explicitly handle grouping).
>
Thanks! This way I get violin plots colored in the correct order.
However, I lose control on panel.violin -- not sure if/how I can regain
that (i.e., the stuff the was done by the panel = function(){} above).
Also, I have noticed that violin plots extend beyond the data range: is
this the default behavior? In ?panel.violin and ?density, I read that
default parameters should allow "the estimated density to drop to
approximately zero at the extremes". For example, the minimum value of
the "count" variable (data = InsectSprays) is zero, but the violin plots
do extend below zero. Am I missing something?
I apologize for my delay in replying, and thank you again for your help.
Kind regards,
Luigi
> -Deepayan
>
>
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.