ggplot2 reverse order of scale_brewer

ggplot2, r

Solution

I think you probably want to select the colors using `brewer.pal` directly and then use `scale_colour_manual`:

library(ggplot2)
library(RColorBrewer)

ggplot(mtcars,aes(x = mpg, y = disp)) + 
    geom_point(aes(colour = factor(cyl))) + 
    scale_colour_manual(values = rev(brewer.pal(3, "BuPu")))

Then you can `rev` the order of the colors there.

As of version 2.0,0 of ggplot there is now a more direct way to do this, see the answer by @pbaylis below.

Problem

Seemingly a very simple thing to do but it took me >30min without finding answer. How do I reverse the order of colors? By looking at documentation for scale_brewer, i figured it can be `formatter=` argument being suspicious. I passed `'rev'` and then `rev`, but they have no effect (no error message, just ignored).

Original source