> ## dummy group ID > group <- sample(rep(1:3, each = 4)) > ## create dummy grouping factor > group <- factor(group, labels = paste("group", 1:3)) > group > > # vector of colours > cols <- c("red", "blue", "green") > ## dummay data to plot > datx <- runif(12) > daty <- runif(12) > > ## plot it > plot(datx, daty, col = cols[group], pch = 16)
Or even more easily with ggplot2: install.packages("ggplot2") library(ggplot2) qplot(datx, daty, colour = group) which also takes care of adding the legend. Hadley -- http://had.co.nz/ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.