I am using plot function on mtcars dataset.
I am trying to add colour to the plots based on mtcars$cyl variable
The distinct values in cyl variable is 4,6 and 8
First i tried this:
plot(x=mtcars$wt, y=mtcars$mpg, col = mtcars$cyl)
I got points plotted on blue,purple and grey colour.
Then I converted cyl variable into a factor and tried the same plot again,
mtcars$fcyl <- as.factor(mtcars$cyl)
plot(x=mtcars$wt, y=mtcars$mpg, col = mtcars$fcyl)
But this time I got black,red and green
I want to understand how assigning the variable as factor changes the colour. What happens behind?
plottry to space evenly the values on the palette. With continuous values obviously two close value will be assigned to close colors. - Moody_Mudskipper