8
When do you normally use factor to color/size encode variables in ggplot2 in R? Example:
ggplot(mtcars) + geom_point(aes(x=mpg, y=drat, colour=gear))
versus:
ggplot(mtcars) + geom_point(aes(x=mpg, y=drat, colour=factor(gear)))
Is the general rule to use factor when the variable being used to determine the shape/size/colour is discrete, and not continuous? Or is there another use of factor in this context? It seems like the first command can be made like the second with the right legend, even without factor. thanks.
edit: I get this when I use the colour=gear:
