I'd like to order factor variables by a corresponding numeric value, so I can create a stacked bar blot in descending order. I looked a lot of Q&As, but couldn't seem to find a solution.
Here is what my data looks like: it has three important variables: name, variable, and value
name variable value
2 bass karen ratio.dis 0.00000000
19 landrieu ratio.dis 0.00000000
20 clinton ratio.dis 0.00000000
22 quigley ratio.dis 0.00000000
25 delbene ratio.dis 0.00000000
> 9 conyers ratio.dis 0.55526316
14 braley ratio.dis 0.56315789
21 franken ratio.dis 0.58245614
10 nadler ratio.dis 0.64298246
12 scott robert ratio.dis 0.70000000
18 cummings ratio.dis 0.72719298
8 jeffries ratio.dis 0.75000000
15 richmond ratio.dis 0.75087719
13 green al ratio.dis 0.77719298
39 jeffries ratio.opt 0.00000000
40 conyers ratio.opt 0.05526316
41 nadler ratio.opt 0.07105263
42 lee sheila ratio.opt 0.08333333
43 scott robert ratio.opt 0.10000000
44 green al ratio.opt 0.11140351
45 braley ratio.opt 0.12456140
Each name appears twice, once for each factor of variable (ratio.opt, ratio.dis). When I try a ggplot, it orders the x-axis alphabetically by name.
ggplot(bills.opt.ordered, aes(x=name, y=value, fill=variable)) +
geom_bar(stat='identity')
Even though the data.frame, bills.opt.ordered, is organized by ascending values, after i tried using the order() command.
To be specific, I want the priority to order by value of EACH factor. When I order by value, I get a graph that orders over all values, which is wrong, because it doesn't split up ratio.dis and ratio.opt first ( i can't paste the graph because I don't have enough reputation points). The right graph would have ascending order for each variable on the same graph, with x-axis being the names.
Thank you for the help!