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?