This question asks about ordering a bar graph according to an unsummarized table. I have a slightly different situation. Here\'s part of my original data:
ex
With newer tidyverse
functions, this becomes much more straightforward (or at least, easy to read for me):
library(tidyverse)
d %>%
mutate_at("pvs_id", as.factor) %>%
mutate(pvs_id = fct_reorder(pvs_id, mqs)) %>%
gather(variable, value, c(mqs, imcs)) %>%
ggplot(aes(x = pvs_id, y = value)) +
geom_col(aes(fill = variable), position = position_dodge())
What it does is:
mqs
(you may use desc(mqs)
for reverse-sorting)melt
)geom_col
(same as geom_bar
with stat="identity"
)