0

I am creating some plots with R and ggplot2, and everything works as expected except by chosing the palette. My intention is to use one of the supplied with brewer but reversed, i.g. the colours of the palette backwards.

p <- ggplot(data=df, aes(x=age, y=patients, fill=factor(age))) + geom_bar(stat="identity")+ scale_fill_brewer(type = "seq", palette = "RdYlGn", direction = -1) 
p <- p + theme_classic() + theme(panel.background = element_blank(), panel.grid.major=element_blank(), panel.grid.minor=element_blank())

Following the instructions from the ggplot manual, the parameter direction set to -1 should do the trick and reverse the colours order. However, when running the code, R complains about the parameter saying it was unused as it was unexpected.

Error in discrete_scale("fill", "brewer", brewer_pal(type, palette), ...) : unused argument (direction = -1)

Any ideas what am I missing?

blamblam
  • 423
  • 6
  • 20
  • 2
    Those are docs for the bleeding-edge-soon-to-be-released version of ggplot2. There is no `direction` parameter for the current ggplot2 package on CRAN. In general, `help(function_name)` is a better way to ensure you are looking at documentation for what you are using than web searches. Reference [this SO q&a](http://stackoverflow.com/questions/8750871/ggplot2-reverse-order-of-scale-brewer) for reversing colorbrewer scales manually (before the impending release) or install the github version of ggplot2. – hrbrmstr Dec 02 '15 at 11:36
  • Thank you! Haven't noticed the package reference version. – blamblam Dec 02 '15 at 11:51

0 Answers0