-3

I want to change the default colors (currently blue and red) of the points in ggplot2 to another color set.

ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy, color=displ<5))

enter image description here

Mike
  • 121
  • 1
  • 1
  • 9

1 Answers1

0
ggplot(data=mpg) + 
    geom_point(mapping = aes(x=displ, y=hwy, color=displ<5)) +
    scale_colour_manual(values=c("gold", "red"))

Here, we use a logical vector, which is converted to numeric to provide a two-color scale i.e. the value for aes(color) is as.integer(mpg$displ < 5).

We then convert this into another two-color scale of our choice, here using named values for colors. This gives:

enter image description here

For more choices for colors, see the following (in package:grDevices, so should be loaded by default):

demo("colors")
dardisco
  • 5,086
  • 2
  • 39
  • 54
Mike
  • 121
  • 1
  • 1
  • 9