I am trying to graph a grouped barplot, where the x-axis contains different states, and within each state, I have values for winter, spring, summer, fall. Basically, on the x-axis, I have 5 states, and each stage is a cluster of bars, and within each cluster I have 4 bars, one for each of winter, spring, summer, fall.
I want to vary the color of the 4 vars in each cluster so that they are different shades of the same color. Say I pick the color blue, I want winter to be the darkest shade of blue and fall to the be lightest shade of blue. I also, want the code to be flexible so it can accomodate more than 4 values within each cluster.
Here is the code I'm working with
# fill = different categories within a group
# x = grouping vars
# y = value (height of bar)
xvar = rlang::sym('states') #grouping var
yvar = rlang::sym('pct_aware')
xlabel = ('state')
ylabel = ('% of respondents')
graphtitle = 'awareness by segmentation'
ylim_max = 100
withingroupvar = rlang::sym('seasons')
legendtitle = "seasons"
p <- ggplot(data = graphinput, aes(x = factor(!!xvar, levels = jobboards), y = !!yvar,
fill = factor(!!withingroupvar, levels =segorder_text)))
p + geom_bar(stat = "identity",
position = position_dodge(0.9)) +
labs(x = xlabel, y = ylabel) +
ggtitle(graphtitle) +
geom_text(aes(label=round(!!yvar,0)), vjust=-0.6, color="black",
position = position_dodge(0.9), size=4) +
scale_fill_manual(name = legendtitle,
values = c('winter'="pink", 'spring' = "aquamarine", 'summer' = "lightblue", 'fall' = "salmon1"),
breaks=segorder_text) +
theme(text = element_text(size = 15)) + ylim(0,ylim_max)
Right now I'm manually assigning color values to each of the 4 seasons. I would like this to be automatic--I only have to pick the base color and R would assign different shades of the same color to each of the seasons.
How should I modify my code to achieve this?