Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ggplot2 for R, how do I reverse the order of the bar colors?

Tags:

r

ggplot2

I have a simple bar graph in ggplot2. I am using the "grey" scale for my bars; the default order is darkest to lightest from left to right. Here's what my code looks like:

  ggplot.3plus<-ggplot(summary.3plus, aes(x=sp1, y=fract.mean, fill=age.cat)) + 
  geom_bar(position=position_dodge())+ coord_cartesian(ylim = c(1, 1.175))+
  geom_errorbar(aes(ymin=fract.mean-se, ymax=fract.mean+se),
                width=.2,                    # Width of the error bars
                position=position_dodge(.9))
  ggplot.3plus<-ggplot.3plus+scale_fill_grey()

I would like to change the color order of the greys to lightest to darkest from left to right, while keeping the bars themselves in the same order. The code I'm using to reverse the order of the color ramp doesn't seem to be working.

like image 574
Luke Avatar asked Jan 16 '23 12:01

Luke


1 Answers

It would be easier with a reproducible example, but what about:

y + scale_fill_grey(start=0.8, end=0.2)
like image 125
csgillespie Avatar answered Jan 28 '23 09:01

csgillespie