[R] a plot of stacked boxes

David Winsemius dwinsemius at comcast.net
Fri Jun 19 18:52:49 CEST 2009


Perhaps this package can help:

http://cran.r-project.org/web/packages/vcd/index.html

Page 4 of this vignette looks like a complete solutions has already  
been programmed:

http://cran.r-project.org/web/packages/vcd/vignettes/residual-shadings.pdf

-- 

On Jun 19, 2009, at 12:41 PM, Osman Al-Radi wrote:

> Hello,
>
> I would like to create a plot composed of stacked boxes (squares or
> rectangles), where the size of the box would represent the frequency  
> of
> observations based on a categorical variable (group), the color would
> represent the proportion of success (binary) within that group  
> (outcome) on
> a predetermined color scale. Ideally the boxes can be stacked from the
> bottom left to the top right based on size. The x and y scales are not
> informative. I am experimenting with the rect() function and loops  
> but I
> wasn't able to generate an appealing graph.
>
> Thanks
>
> Osman
>
> Here is simulated data set
>
> group<-rep(c('a','b','c','d','e','f','g'),c(100,20,300,40,2,10,40))
>
> outcome<-c(sample(c(0,1),100,rep=T,p=c(0.98,0.02)),
>
> sample(c(0,1),20,rep=T,p=c(0.9,0.1)),
>
> sample(c(0,1),300,rep=T,p=c(0.99,0.01)),
>
>  sample(c(0,1),40,rep=T,p=c(0.95,0.05)),
>
>   sample(c(0,1),2,rep=T,p=c(0.5,0.5)),
>
>    sample(c(0,1),10,rep=T,p=c(0.9,0.1)),
>
>     sample(c(0,1),40,rep=T,p=c(0.8,0.2)))
>
> df<-data.frame(group=group,outcome=as.numeric(outcome))
>
>
> Osman O. Al-Radi, MD, MSc, FRCSC
> Staff Cardiovascular Surgeon
> Co-medical director, Tissue Bank
> The Hospital for Sick Children
> University of Toronto, Canada-

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list