Sometimes, it can be interesting to distinguish the values by a group of data (i.e. factor level data).
ggplot(mtcars, aes(x = mpg, y = drat)) +
geom_point(aes(color = factor(gear)))
- The aes() inside the geom_point() controls the color of the group. The group should be a factor variable. Thus, you convert the variable gear in a factor.
- Altogether, you have the code aes(color = factor(gear)) that change the color of the dots.