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

Matthieu Dubois
2009-05-23T11:41:47Z

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