[R] (Grouped + Stacked) Barplot

David Winsemius dwinsemius at comcast.net
Thu Dec 3 04:50:34 CET 2009


On Dec 2, 2009, at 10:25 PM, Xin Ge wrote:

> Hi All,
>
> I have googled and tried finding if someone has ever tried producing
> (Grouped + Stacked) Barplot. I couldn't find one.

I think you need to define some dummy Factor1 categories with zero  
heights and blank labels to separate your groups. Once that is done,  
you can just use typical stacked bar graphs.

(Another barplot function to consider:

http://pbil.univ-lyon1.fr/library/gregmisc/html/barplot2.html
  )
>
> My data needs to be reshaped, but once it is done it would be  
> something like
> this:
>
> Factor1    Factor2    Factor3    Value
> A    X    P    10
> A    X    Q    20
> A    Y    P    20
> A    Y    Q    5
> A    Z    P    20
> A    Z    Q    10
> B    X    P    20
> B    X    Q    10
> B    Y    P    30
> B    Y    Q    50
> B    Z    P    10
> B    Z    Q    20
>
> There are three categorical variables (Factor1, Factor2, and Factor3  
> having
> 2,3, and 2 levels resp.). I'm trying to plot "Factor1" on x axis --  
> each
> level of this factor should have three (grouped) bars (one for each  
> level of
> Factor2). Which will further be stacked by each level of Factor3.
>
> Can anyone guide me please, thanks,
> ~Xin


David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list