Skip to content
Prev 317943 / 398506 Next

Scatterplot, Color by Grade Category

On 02/20/2013 07:44 PM, David Arnold wrote:
Hi David,
As factors can be converted to numbers beginning with 1, you can do it 
easily:

plot(data$hours,data$level,pch=as.numeric(data$grade),
  col=as.numeric(data$grade))

Obviously if you want other than symbols 1, 2 and 3 in colors black, red 
and green, you can create vectors of symbol numbers and colors:

mysymbols<-c(4,6,19)
mycolors<-c("palevioletred4","mediumorchid3","lightgoldenrod2")

and then index into them:

plot(data$hours,data$level,pch=mysymbols[as.numeric(data$grade)],
  col=mycolors[as.numeric(data$grade)])

Jim