title: Arrange rows in heatmap (ggplot geom_tile)
body: <p>I'm using dplyr and ggplot to create heatmaps. (I've used the useful -likert- package in the past, but want more customization.) The one remaining task to do is rearrange rows by one column in the heatmap. </p>
  
  <p>In the simplified example below, how would I arrange the rows so that the "A lot" column descends from high to low? I.e., The Camping row would be at the top, and Swimming would be underneath? In real life, there are 22 rows, so I don't want to arrange them manually.</p>
  
  <p>Thanks for your help!</p>
  
  <pre><code># not shown: use dplyr (gather, count, mutate) to create 
  # the following simplified data.frame in long format:
  
  df &lt;- tibble(
    value = c("A little","A little","A lot","A lot","Don't know","Don't know", "Not at all","Not at all"),
    Item = rep(c("Swimming","Camping"), 4),
    percent = c(10, 14, 50, 83, 20, .25, 10, 3)
  )
  df
  
  # manually set column order (non-alphabetical)
  col_order &lt;- c("Not at all", "A little", "A lot", "Don't know")
  df$value &lt;- factor(df$value, levels = col_order)
  
  # plot results
  p &lt;- ggplot(df, aes(x = value, 
                           y = Item)) +
    geom_tile(aes(fill = percent)) + 
    geom_text(aes(label = paste0(round(percent, 0), sep = "%")),
              size = 4, colour = "black") +
    scale_fill_gradient(low = "#e5ebf0", 
                        high = "#325f87",
                        limits = c(0, 100)) +
    xlab("") + 
    ylab("") + 
    theme_tufte() # + additional customization
  
  print(p)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Yxq9g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yxq9g.png" alt="enter image description here"></a></p>