Reversing default scale gradient ggplot2
?scale_colour_gradient
shows the default values of low = "#132B43"
and high = "#56B1F7"
.
Simply switch those around:
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density)) +
scale_fill_continuous(high = "#132B43", low = "#56B1F7")
Personally, I think this is less intuitive than the default.
Alternatively, you can use a reverse scale, but this will also flip the legend to start at the top:
ggplot(faithfuld, aes(waiting, eruptions)) +
geom_raster(aes(fill = density)) +
scale_fill_continuous(trans = 'reverse')
you can use the color palettes from RColorBrewer
(link) library and assign the direction of the color gradient
library(RColorBrewer)
library(ggplot2)
ggplot(df, aes(x, y)) +
geom_tile(aes(fill = z, width = w), colour = "grey50") +
scale_fill_distiller(palette ="RdBu", direction = -1) # or direction=1
# data
df <- data.frame( x = rep(c(2, 5, 7, 9, 12), 2),
y = rep(c(1, 2), each = 5),
z = rep(1:5, each = 2),
w = rep(diff(c(0, 4, 6, 8, 10, 14)), 2))