[R] Stripchart: way to get different colour for each group

David Winsemius dwinsemius at comcast.net
Tue Dec 1 08:07:10 CET 2009


On Dec 1, 2009, at 12:42 AM, johannes rara wrote:

> Hi,
>
> Is there a way to get different colour based on group when plotting  
> stripchart?
>
> mydata <- data.frame(val1 = c(1.1, 3.2, 4.1, 2.5, 6.2, 5.3, 4.5, 2.2,
> 4.7, 2.7), val2 = c(4.2, 5.3, 3.4, 2.6, 5.3, 6.2, 7.7, 4.8, 3.4, 2.1),
> group = rep(0:1, 5))
> mydata.stack <- stack(mydata, select=-group)
>
> stripchart(values ~ ind,
>          data=mydata.stack,
>          vertical=T,
>          at=c(1.25, 1.75),
>          pch=15,
>          col="red")
>
> I would like to get different colour for the two groups (based on
> group variable). I tried something like
>
> stripchart(values ~ ind,
>          data=mydata.stack,
>          vertical=T,
>          at=c(1.25, 1.75),
>          pch=15,
>          col=c("red", "yeallow")[mydata$group])

Doesn't this work?

stripchart(values ~ ind,
          data=mydata.stack,
          vertical=T,
          at=c(1.25, 1.75),
          pch=15,
          col=c("red", "yellow") )

I would not think that mydata$group would be "in sync" with the  
dataset that you are passing to stripchart.

-- 
David

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list