You essentially want to fill by one thing, and order by another. A solution is thus to pry them apart and create a separate 'order' variable. Of note, I don't know if sorting your bars by value instead of having the same sequence each 'group' makes your plot more understandable.....
create some data:
library(data.table)
set.seed(123)
dat <- expand.grid(group=LETTERS[1:3],
subgroup=LETTERS[1:3])
dat$value <- runif(nrow(dat))
setDT(dat)
Create the order variable:
dat[,order:=order(value),by=group]
Create the plot
p1 <- ggplot(dat, aes(x=group,y=value, fill=subgroup,group=order))+
geom_bar(aes(group=order),position="dodge", stat="identity") +
coord_flip()
p1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…