Skip to content
Prev 315571 / 398503 Next

Getting discrete colors on plot

Hi
Learn to use factors.

 str(mydata)
'data.frame':   5 obs. of  7 variables:
 $ id      : num  1 2 3 4 5
 $ x1      : num  5 2 3 5 1
 $ x2      : num  4 1 3 5 1
 $ x3      : num  5 2 3 5 1
 $ x4      : num  4 3 3 5 1
 $ x5      : num  3 1 3 5 1
 $ colorvar: num  3 1 2 3 1
Your colorvar is numeric therefore the scale. If you want to make it discrete change it to factor.

mydata_long$colorvar<-factor(mydata_long$colorvar)

and use your function to see the difference.

Regards
Petr