Categories

Nov 14, 2019 in R Language
Q: Scatter plot with groups in R language

1 Answer

Nov 14, 2019

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.
Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

Madanswer
Jul 28, 2019 in R Language
Nov 14, 2019 in R Language
Nov 14, 2019 in R Language
...