[R] multi-color plot

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Thu Feb 13 04:09:02 CET 2003


Saurav Pathak wrote:
> hi all,
> 
> i am trying to make multi-color plots.  that is, i generally use,
> 
> 	plot(x, y, type="n")
> 	text(x, y, labels=class)
> 
> here, the vector class denotes the class of each point.  there are
> usually 3-4 classes of points.  how may i display the different
> classes in different colors?
> 

Use the col argument in text, as in:

R> plot(x=1:26,y=rep(0:1,13),type="n")
R> text(x=1:26,y=0.5,labels=letters,col=terrain.colors(26))
R>

where terrain.colors(26) is:

R> terrain.colors(26)
  [1] "#00A600" "#0EAB00" "#1DB000"
  [4] "#2DB600" "#3EBB00" "#50C000"
  [7] "#63C600" "#76CB00" "#8BD000"
[10] "#A0D600" "#B6DB00" "#CEE000"
[13] "#E6E600" "#E6D612" "#E7C924"
[16] "#E8BF36" "#E9B848" "#EAB35A"
[19] "#EBB16D" "#ECB27F" "#EDB592"
[22] "#EEBCA5" "#EFC5B8" "#F0D1CB"
[25] "#F1E0DF" "#F2F2F2"

Also, I would avoid using `class' as a variable name since it has a 
special definition in R.


Hope this helps,
Sundar




More information about the R-help mailing list