d4ynn
d4ynn

Reputation: 27

ggplot2: Reversing the standard color gradient for a continuous variable

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.

Upvotes: 1

Views: 1779

Answers (1)

Martin Schmelzer
Martin Schmelzer

Reputation: 23909

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

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

Upvotes: 2

Related Questions