ggplot2: Reversing the standard color gradient for a continuous variable

1.7k views Asked by At

I keep thinking that there must be an absolutely simple answer to my question, but I just can't seem to find it. Take this example plot:

library(ggplot2)
qplot(cty, displ, colour=displ, data=mpg)

This makes low values of displ appear in a dark blue and high values of displ appear in a light blue.

All I want to do is reverse the color gradient, because that seems more intuitive to me. I want low values of displ to have the light blue color and high values to have the dark blue color.

I know of this possibility to manually specify colors:

scale_colour_gradient(low="grey", high="black")

But I want to use the default colors, just in reverse.

1

There are 1 answers

0
Martin Schmelzer On BEST ANSWER

Just take the default color codes from ?scale_colour_gradient and swap the arguments:

scale_colour_gradient(high = "#132B43", low = "#56B1F7")