1

how to order the Heatmap by the names of the Candidates on the y axis ?

This is my current code which does an opposite order comparing to what I want (and I want an order from A to Z by the name):

ggplot(data = primary_results, aes(y = candidate, x = state_abbreviation)) +     
geom_tile(aes(fill = fraction_votes)) + 
scale_fill_viridis(option = "plasma") +
theme_solarized_2() +
xlab("State") +
ylab("Candidate") +
guides(fill = guide_legend(title="Fraction Votes"))

MyCurrentHeatmap:

enter image description here

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • 1
    [Show us your data!](http://stackoverflow.com/a/5963610/2005219) – Edward R. Mazurek May 24 '16 at 19:03
  • something like that....primary_results$candidate <- factor(primary_results$candidate, levels =c("Jeb Bush","...", "D. Trump")) – MLavoie May 24 '16 at 19:16
  • Either reorder the factor in your data, `primary_results$candiate = factor(primary_results$candiate, levels = rev(levels(primary_results$candidate)))` or similarly reorder in `scale_y_discrete`. – Gregor Thomas May 24 '16 at 19:18
  • Possible dupes: [how to reverse order y axis values ggplot2](http://stackoverflow.com/q/16223435/903061) and [ggplot2: Reversing the order of discrete categories on y-axis in scatterplot](http://stackoverflow.com/q/31955772/903061) – Gregor Thomas May 24 '16 at 19:22

0 Answers0