I found posts like How to control ordering of stacked bar chart using identity on ggplot2 where the order of factors can be re-leveled when the bar plots have the same factors in them, or using a numeric to order the stacked bars, but I want to create a stacked bar plots where each stack has its own unique factors.
test <- data.frame(unique_factors = c("stack", "bars", "in", "this", "exact", "order"),
length = c(1,5,3,2,6,1),
groups = c("1", "1", "1", "2", "2", "2"))
ggplot(test, aes(x = groups, y = length)) +
geom_bar(stat = "identity", aes(fill = unique_factors, levels=c("stack", "bars", "in", "this", "exact", "order")))
Current Output
Desired Output
Is it possible to achieve this effect - if so, how? Thank you so much for your help!