title: ordering a stacked bar ggplot2
body: <p>I analysed multiple related questions but couldn't solve the problem.</p>
  
  <p>Here are my data, called <code>fam</code>:</p>
  
  <pre><code>structure(list(familiarity = structure(c(1L, 1L, 1L, 1L, 1L, 
  1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 
  2L, 2L, 2L, 2L, 2L, 2L), .Label = c("familiar", "not familiar", 
  "not sure"), class = "factor"), idiom = structure(c(7L, 8L, 1L, 
  5L, 4L, 9L, 3L, 6L, 2L, 6L, 2L, 3L, 4L, 9L, 7L, 8L, 1L, 5L, 9L, 
  2L, 3L, 4L, 6L, 7L, 8L, 1L, 5L), .Label = c("be in the same boat", 
  "beat one’s chest", "chew the fat", "just around the corner", 
  "kick the bucket", "left hanging in the air", "sweep sth under the carpet", 
  "take the plunge", "tighten one’s belt"), class = "factor"), 
  frequency = c(11L, 11L, 11L, 11L, 10L, 8L, 8L, 7L, 6L, 4L, 
  3L, 2L, 1L, 1L, 0L, 0L, 0L, 0L, 2L, 2L, 1L, 0L, 0L, 0L, 0L, 
  0L, 0L)), .Names = c("familiarity", "idiom", "frequency"), class = "data.frame", 
  row.names = c(NA, -27L))
  </code></pre>
  
  <p>I figured out how to do the stacked bar plot. Here's what I got:</p>
  
  <p><img src="https://i.stack.imgur.com/kWg7b.png" alt="Plot1"></p>
  
  <p>Here's my code, so far:</p>
  
  <pre><code>ggplot(data = fam, aes(x = idioms, y = frequency, fill = familiarity, width = 0.5)) + 
      geom_bar(stat = 'identity') + 
      coord_flip() + 
      scale_fill_manual(values = c('limegreen', 'purple', 'red1')) + 
      theme(axis.title.y = element_blank(), 
            axis.title.x = element_text(size = 10), 
            axis.text.x = element_text(size = 10), 
            axis.text.y = element_text(size = 10), 
            legend.text = element_text(size_10), 
            text = element_text(size = 10),
            plot.margin = unit(c(0.3, 0.5, 0.3, 0.8), 'cm')) + 
      scale_y_continuous(breaks = pretty_breaks()) + 
      labs(y = "number of responses") + 
      labs = (fill = "")
  </code></pre>
  
  <p>I'd like to get an ordered stacked bar with respect to 'familiarity'. In crude terms, I'd like to get the highest familiarity scores (the green bars) first, then 'familiar' and 'not sure', and then 'familiar', 'not sure', 'not familiar'. Basically, descending quality. </p>
  
  <p>I'd be grateful for any suggestions.</p>