Re: [R] Multiple color schemes for barchart (lattice)

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Wed, 06 Jun 2007 13:44:18 -0700

On 6/6/07, Sarah Hawley <sarah_at_canaryfoundation.org> wrote:
> Hello R-help.
>
> I am trying to make a stacked barplot where the color of the sections of
> each bar depend on another variable.
>
> > myData[1:11,]
> score percent marker cellType Malignant
> 1 0 100.00000 ESR1 (ER) Bladder.M(5) TRUE
> 2 0 80.00000 PAX8 Bladder.M(5) TRUE
> 3 1 20.00000 PAX8 Bladder.M(5) TRUE
> 4 0 100.00000 ESR1 (ER) Brain.N(3) FALSE
> 5 0 100.00000 PAX8 Brain.N(3) FALSE
> 6 3 100.00000 ESR1 (ER) Breast.M(11) TRUE
> 7 0 100.00000 PAX8 Breast.M(11) TRUE
> 8 0 36.36364 ESR1 (ER) Cervix.M(11) TRUE
> 9 1 9.09091 ESR1 (ER) Cervix.M(11) TRUE
> 10 2 18.18182 ESR1 (ER) Cervix.M(11) TRUE
> 11 3 36.36364 ESR1 (ER) Cervix.M(11) TRUE
>
> palette <- palette(gray(seq(0, 1,len=4)))
> trellis.par.set(list(par.xlab.text=list(cex=0.85)
> , superpose.polygon=list(col=palette())
> , axis.text=list(cex=0.8)))
>
>
> barchart(percent~cellType|marker
> , groups=score
> , data=myData
> , stack=TRUE
> , xlab='N=Normal/Benign, M=Malignant'
> , ylab='Percentage of Cores Staining'
> , color=palette()
> , auto.key = list(points = FALSE, rectangles = TRUE, space = "top")
> , scales=list(x=list(rot=70))
> , layout=c(1,2))
>
> I would like to make the color scheme of the bar differ according to the
> variable 'Malignant' and add a second color scheme to the key.

I may not have understood what you are looking for, but it seems like you just need

groups = interaction(score, Malignant)

For example,

palette <- palette(gray(seq(0, 1,len=8)))

trellis.par.set(list(par.xlab.text=list(cex=0.85)

                  , superpose.polygon=list(col=palette())
                  , axis.text=list(cex=0.8)))

barchart(percent~cellType|marker
       , groups= interaction(score, Malignant)
       , data=myData
       , stack=TRUE
       , xlab='N=Normal/Benign, M=Malignant'
       , ylab='Percentage of Cores Staining'
       # , color=palette() # not doing anything
       , auto.key = list(points = FALSE, rectangles = TRUE, space =
"top", columns = 2)
       , scales=list(x=list(rot=70))
       , layout=c(1,2))

-Deepayan



R-help_at_stat.math.ethz.ch 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. Received on Wed 06 Jun 2007 - 20:57:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Jun 2007 - 21:32:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.