#sample code
ggplot(diamonds, aes(x=price, fill=cut)) +
geom_histogram(position="dodge", binwidth=1000) +
scale_fill_brewer(palette="RdYlBu")
Running ggplot2 0.9, win 7, R 2.15
Thank you in advance for your help.
Tyler Rinker
Reverse the order in the data
diamonds$cut = factor(diamonds$cut, levels=rev(levels(diamonds$cut)))
ggplot(diamonds, aes(x=price, fill=cut)) +
geom_histogram(position="dodge", binwidth=1000) +
scale_fill_brewer(palette="RdYlBu")
Or reverse the palette mapping
library("ggplot2")
library("RColorBrewer")
colours= brewer.pal(name="RdYlBu", n=nlevels(diamonds$cut))
names(colours)= rev(levels(diamonds$cut))
ggplot(diamonds, aes(x=price, fill=cut)) +
geom_histogram(position="dodge", binwidth=1000) +
scale_fill_manual(values=colours)
Jean-Olivier Irisson
---
Observatoire Océanologique
Station Zoologique, B.P. 28, Chemin du Lazaret
06230 Villefranche-sur-Mer
Tel: +33 04 93 76 38 04
Mob: +33 06 21 05 19 90
http://jo.irisson.com/
----------------------------------------
> Subject: Re: Reverse scale_fill_brewer
> From: iri...@normalesup.org
> Date: Thu, 19 Apr 2012 09:30:23 +0200
> CC: ggp...@googlegroups.com
> To: tyler_...@hotmail.com