library(tidyverse)
Data_stacked = tribble(~Cond, ~Group, ~Amount,
"A", "X", 1,
"B", "X", 4,
"C", "X", 2,
"D", "X", 6,
"E", "Y", 7,
"F", "Y", 5,
"G", "Y", 3,
"H", "Y", 4 )
Another workaround, defining the order seperately by sorting the initial dataframe.
order = Data_stacked %>%
arrange(Group, desc(Amount)) %>%
pull(Cond)
# ordered
ggplot(Data_stacked, aes(x=fct_reorder(Cond, order), y=Amount, fill=Group)) + theme_bw() +
geom_col()
If necessarry you can put this in one line, however I wouldn't recommend this.
ggplot(Data_stacked, aes(x=fct_reorder(Cond,
pull(arrange(Data_stacked, Group, desc(Amount)), Cond)),
y=Amount, fill=Group)) + theme_bw() +
geom_col()