in R Language by
Q:
Scatter plot with groups in R language

▼ Show 1 Answer

0 votes
by

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)))

Code Explanation

  • 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.
Learn More with Madanswer

Related questions

+2 votes
asked Jul 28, 2019 in R Language by Aarav2017
...