0

I have below simple scatterplot generated with this code:

library(ggplot2)
ggplot(Orange, aes(x = age, y = circumference)) + geom_point()

enter image description here

Now I want to change scatterplot of this such that each point has a different according to the value of its “Tree” variable and change the default ggplot2 coloring behavior, use more sharp colors like red, blue, orange, green, etc.

fagoz
  • 49
  • 4
  • 3
    `geom_point(color = factor(Tree))`. Take a look at the default colors it assigns - if you don't like them, check out the `RColorBrewer` package – Punintended Mar 11 '18 at 23:21
  • I need to change scatterplot of this such that each point has a different according to the value of its “Tree” variable – fagoz Mar 11 '18 at 23:27

1 Answers1

1

You can also take another variable in the dataset and use it as a "color" (totally not intuitive, but it works). I do like how this automatically creates the legend though.

ggplot(Orange, aes(x = age, y = circumference, color=Tree)) + geom_point()

enter image description here

mysteRious
  • 4,102
  • 2
  • 16
  • 36