Hello stack overflow community,
I'm trying to find a way to colour two columns that I managed to put together in a stacked barplot. The X axis represents the months, and the columns represent both the year (there is 'n-1' year and 'n' year) and type of business. Type of business was easy to colour because it is the fill, but I can't find a way to have different colours for 'n-1' year and 'n' year columns, or a way to clarify that each column per month represents a different year.
For clarity purposes, this is what the data looks like:
This is the code I used so far:
barwidth = 0.35
ggplot() +
geom_bar(data = BUSINESS_18,
mapping = aes(x=Month, y=GWP_mio, fill=Business),
stat ="identity",
position = "stack",
width = barwidth) +
geom_bar(data = BUSINESS_19,
mapping = aes(x=as.numeric(Month) + as.numeric(barwidth) + 0.05, y=GWP_mio, fill=Business),
stat ="identity",
position = "stack",
width = barwidth) +
theme_ipsum() +
scale_fill_manual(values = c("#009E73","Darkblue")) +
scale_y_continuous(breaks=seq(0,18000000,1000000), labels = scales::comma_format(scale = 1/1000000,
accuracy = .1), limits = c(0,18000000)) +
ggtitle('GWP development') +
theme(plot.title = element_text(hjust=0.5, size=14, family="Calibri", face="bold"),
legend.title = element_text(size=11, family="Calibri", face="bold"),
axis.title.x = element_text(hjust=1, size=11, family="Calibri", face="bold"),
axis.text.x = element_text(angle=0, hjust=1, size=11, family="Calibri"),
axis.title.y = element_text(angle=0, hjust=1, size=10, family="Calibri", face="bold"))
And a picture of the graph, so you can more easily understand what I mean (no differentiation between the two columns per month):
Any help would be highly appreciated! Many thanks in advance.