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))
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:
For more choices for colors, see the following (in package:grDevices
, so should be loaded by default):
demo("colors")