I need to manually set colors for each group in a barplot. I currently have the fill = time and this is currently determining the colors. We have 5 brands and the values for 2 separate months per brand. I need to group by brand but also need a way to display which bar represents which month(time), I can currently do this however I want to color each bar group. eg. brand1 bars = red, brand2 bars = blue ect whilst still having fill = time
Here is my code:
colors <- c("#98999B", "#F4C400", "#CB003D", "#6BABE5", "#E65400", "#542C82")
time <- c("February 2017","March 2017","February 2017","March 2017","February 2017","March 2017","February 2017","March 2017","February 2017","March 2017")
value <- as.numeric(c("3.08","3.64","1.61","1.81","-1.02","-1.09","-5.23","-5.08","-1.51","-1.43"))
brand <- c("brand1","brand1","brand2","brand2","brand3","brand3","brand4","brand4","brand5","brand5")
Monthly_BMS_df <- as.data.table(cbind(time,value,brand))
bar <- ggplot(Monthly_BMS_df, aes(brand, value, fill = time)) +
geom_bar(stat="identity", position = "dodge") +
theme(legend.position='none') + scale_fill_manual(values=colors)
ggplotly(bar, width=1000,height=350)