When do you usually use factorfor coding color / size variables in ggplot2 in R? Example:
ggplot(mtcars) + geom_point(aes(x=mpg, y=drat, colour=gear))
against
ggplot(mtcars) + geom_point(aes(x=mpg, y=drat, colour=factor(gear)))
Is it a general rule to use factorwhen a variable used to define shape / size / color is discrete and not continuous? Or is there another use factorin this context? It seems that the first team can be made as the second with the right legend, even without factor. thank.
edit: I get this when I use colour=gear:

source
share