[R] color code from csv

hadley wickham h.wickham at gmail.com
Sat Oct 4 00:36:01 CEST 2008


On Fri, Oct 3, 2008 at 2:10 PM, kerfuffle <pswi at ceh.ac.uk> wrote:
>
> hi folks,
>
> this is driving me up the wall.  Apologies for posting twice in the same
> week, I'm writing up a thesis.  I wish to color-code some dots in an xy
> plot.  I've got a csv file with various elements, one of which is the
> color-key (with the header 'color').  If the color-key is decimal (eg.
> 1,2,3) then I can use
> plot (X ~ Y, col=data$color)

You might want to try using ggplot2 instead:

install.packages("ggplot2")
library(ggplot2)
qplot(Y, X, data=data, colour = color)

That will automatically pick a nice colour scale for you and draw a
legend.  You can see some examples of
http://had.co.nz/ggplot2/geom_point.html

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list