reverse palette colors?

7,618 views
Skip to first unread message

Fred Oswald

unread,
Mar 26, 2012, 2:26:05 PM3/26/12
to ggp...@googlegroups.com, seydahmet ercan
Hello - I have a simple problem and hopefully a simple solution...that I cannot find.
I've attached the data and R code (the latter is also below) for a histogram generated by the code and data (please load ggplot2 and RColorBrewer packages).
All I want to do is reverse the palette (dark = light and light = dark).  

Hm, as long as I'm being picky(!), I'd also like the light color not to be so light as to be indiscernible (i.e., not white).
Thanks for any help on this!

Fred

==
R Code for histogram:

m <- read.csv("example.csv")
a <- cut(m$var.eff.size,5)
bin <- c(.25, .50, .75)
xi <- quantile(m$e, bin)
mg <- qplot(m$e, data = meta, geom = "histogram", fill=a, main="Frequency Distribution")
mg +  opts(panel.background = theme_rect()) +
geom_vline(xintercept = xi) +
labs(x="e", y="f", fill="e") +
scale_fill_brewer(type="seq")

-
Fred Oswald
Associate Professor
Department of Psychology, Rice University
www.owlnet.rice.edu/~foswald
example.csv
Oswald - R help.txt

David Kahle

unread,
Mar 26, 2012, 4:14:15 PM3/26/12
to Fred Oswald, ggp...@googlegroups.com, seydahmet ercan
Hi Fred -

The below works easily, although I'm sure there's a way to do it directly from scale_fill_brewer.

m <- read.csv('example.csv')
a <- cut(m$var.eff.size, 5)
bin <- .25*(1:3)
xi <- quantile(m$effect.size, bin)
qplot(effect.size, data = m, geom = 'histogram'
    fill = a, main = 'Frequency Distribution') +
  geom_vline(xintercept = xi) +
  theme_bw() + labs(x = 'e', y = 'f', fill = 'e') +
  scale_fill_brewer(type = 'seq')


# straight reversal
fills <- rev(brewer.pal(5, 'Blues'))
qplot(effect.size, data = m, geom = 'histogram'
    fill = a, main = 'Frequency Distribution') +
  geom_vline(xintercept = xi) +
  theme_bw() + labs(x = 'e', y = 'f', fill = 'e') +
  scale_fill_manual(values = fills)


# darker
fills <- rev(brewer.pal(7, 'Blues'))[1:5
qplot(effect.size, data = m, geom = 'histogram'
    fill = a, main = 'Frequency Distribution') +
  geom_vline(xintercept = xi) +
  theme_bw() + labs(x = 'e', y = 'f', fill = 'e') +
  scale_fill_manual(values = fills)


# in general
fills <- c('red','green','blue','purple','orange')
qplot(effect.size, data = m, geom = 'histogram'
    fill = a, main = 'Frequency Distribution') +
  geom_vline(xintercept = xi) +
  theme_bw() + labs(x = 'e', y = 'f', fill = 'e') +
  scale_fill_manual(values = fills)


Cheers
david.

PS - nice to see ggplot2 has made it into the Psych department at Rice!


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
<Oswald - R help.txt><example.csv>



-------------------------------------------------------------
-------------------------------------------------------------

David J. Kahle, Ph.D.
Assistant Professor of Statistical Science
Department of Statistical Science
Baylor University
One Bear Place #97140
Waco, Texas 76798



Reply all
Reply to author
Forward
0 new messages