Мы можем использовать функцию reorder()
в пределах aes()
, т. Е.
> ggplot(data = s, aes(x=reorder(as.factor(seq), -depth), y=count, fill = depth)) +
geom_bar(stat = 'identity')
Данные:
> dput(s)
structure(list(count = c(10, 20, 30, 25, 40, 12), depth = c(1,
2, 1, 3, 2, 2), seq = structure(c(1L, 2L, 6L, 4L, 3L, 5L), .Label = c("A",
"AA", "AAA", "C", "G", "TT"), class = "factor")), .Names = c("count",
"depth", "seq"), row.names = c(NA, -6L), class = "data.frame")