[R] how to adding colors to data points in scatter plot in R?

Matthieu Dubois matthdub at gmail.com
Sat May 23 13:41:47 CEST 2009


Simply use the col paramater, with a factor to index the colors. 

Example: 
# generate some data
x <- rnom(100)
y <- rnorm(x)
z <- as.factor(rbinom(x,1,0.5))

# plot
plot(x,y, col=c('red','blue')[z])

HTH, 

Matthieu



More information about the R-help mailing list