I am using RBrewer to to manually colour my ggplot bar chart but i'm having no luck.
I create my colour palette of blues and then assign it to a function for it to ramp.
blues <- brewer.pal(9, "Blues")
blue_range <- colorRamp(blues)
I then plot my stacked bar chart, where I know i have 20 groups.
ggplot(Month.Summary, aes(x=Calendar.Month, y = Measure, fill = Groups)) + geom_bar(stat="Identity", position = "fill") +scale_fill_manual(values = blue_range(20))
I unfortunately get the following error:
Error: Insufficient values in manual scale. 20 needed but only 3 provided.
I'm using Groups
as my fill, where I know there are 2 instances. I'm passing 20 to the blue_range
function so i'm not sure why it's saying i'm only passing 3 colours.
The
blue_range()
function expects values between 0 and 1. To get the discrete palette, pass a sequence to this function:This should work in the
ggplot()
call -- not tested because you didn't provide a reproducible example.Note that recent
ggplot2
hasscale_fill_distiller()
which provides a similar functionality with a more convenient interface.