[R] Colors vector based on group

David Winsemius dwinsemius at comcast.net
Mon Feb 6 16:48:26 CET 2012


On Feb 6, 2012, at 9:40 AM, Filoche wrote:

> Hi everyone.
>
> I have a vector like this:
>
> x =
> c
> (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2
> )
>
> I would like to associate a colour to each of these entry. For  
> example, I
> could use /topo.colors(3)/ (since I have 3 groups).
>
> I know it is easy to do this with  /if/else/ statements, but I would  
> like to
> find a proper way to do this.
>

topo.colors(3)[c(1,2,3,1,2,3)]
[1] "#4C00FFFF" "#00FF4DFF" "#FFFF00FF" "#4C00FFFF" "#00FF4DFF"  
"#FFFF00FF"

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list