I have a stacked & grouped plot. I have numbers of tomatoes and apples (two groups) for 3 different years (stacked). I want that the years of the tomotoes have a different color than the years of the apples, so that is it clear which stack is about which fruit. So, for example, first year of tomatoes is dark-blue and for apples is light-blue, second year of tomatoes is dark-green and for apples light-green.
My currunt code is this:
ggplot() +
geom_bar(data = dataset,
mapping = aes(x = var_2, y = number , fill = as.factor(year)),
stat="identity",
position='stack',
width = 35) +
geom_bar(data = dataset,
mapping = aes(x = as.numeric(var_1) + 35 + 0.05 , y = number, fill = as.factor(year)),
stat="identity",
position='stack',
width = barwidth)+
scale_x_discrete(labels = function(x) str_wrap(x, width = 40)) +
#scale_fill_manual(values = #current colors but that doesnt work +
coord_flip()
Some ideas here maybe?
Edit: also fine to add a pattern to one of the two types of fruit.