I am creating multiple series of plots for different vegetation types and using filter to subset the individual veg type being plotted. These are bar graphs and I'd like to use the same palette of colors to indicate successional class, but use more descriptive labels in the legend. I have 1 column for the x variable/legend labels and another for the symbol colors.
I used the symbol column in aes for fill, but this is causing the legend labels to default to the symbol values rather than the x variable values. When I use scale_fill_manual() to assign the label column (df$symbol) it pulls in values from outside of the subset range. Is there a way to use the x variable column for my legend labels without manually entering them?
Thank you!
Example
make <- c('volvo','volvo','volvo','volvo',
'mazda','mazda','mazda','mazda',
'toyota','toyota','toyota','toyota')
label <- c('alpha','beta','charlie','delta',
'echo','foxtrot','golf','hotel',
'juliett','kilo','lima','mike')
symbol <- rep(c('a','b','c','d'), 3)
length <- sample(40, size = 12, replace = TRUE)
df <- data.frame("make" = make, "length" = length, "label" = label, "symbol" = symbol)
Symbol_col = c(a ='grey', b ='red', c = 'green', d = 'gold')
ggplot(filter(df, make == 'volvo'), aes(x = label, y = length, fill= symbol)) +
geom_col() +
scale_fill_manual(values = Symbol_col)