title: Reordering groups in Likert plots with R
body: <p>I'm using <a href="https://github.com/jbryer/likert" rel="noreferrer">the <code>jbryer/likert</code> package</a> to plot Likert data.</p>
  
  <p>Consider the response table, called <code>items</code>—here, <code>A</code>, <code>B</code>, and so on are the column names, not part of the data:</p>
  
  <pre><code>A B C D
  5 4 5 4
  3 3 3 4
  2 2 2 2
  2 2 2 3
  5 3 6 7
  3 3 5 4
  </code></pre>
  
  <p>And the following code:</p>
  
  <pre><code>choices  = c("Very low", "Low", "Rather low", "Neither low nor high", "Rather high", "High", "Very high")
  for(i in 1:ncol(items)) {
    items[,i] = factor(items[,i], levels=1:7, labels=choices, ordered=TRUE)
  }
  </code></pre>
  
  <p>Now, we transform this into the <code>likert</code> data and plot it, which overrides the built-in plot function with one that uses <code>ggplot</code>:</p>
  
  <pre><code>plot(likert(items), ordered=FALSE)
  </code></pre>
  
  <p>This gives me:</p>
  
  <p><img src="https://i.stack.imgur.com/NbkBX.png" alt=""></p>
  
  <p>Cool. All ordered. But <code>A</code>, <code>B</code>, etc. are not meaningful as descriptors for the conditions, and I'd like to override them:</p>
  
  <pre><code>names(items) = c("LT", "ST", "SemTag", "SemTagContext")
  </code></pre>
  
  <p>Which gives me the wrong order:</p>
  
  <p><img src="https://i.stack.imgur.com/Z1LHq.png" alt=""></p>
  
  <p>See how <code>ST</code> comes first, although it's the name for <code>B</code>? My ordering got changed to <code>B</code>, <code>D</code>, <code>C</code>, <code>A</code>.</p>
  
  <p>How can I make it preserve the order and return the bars in <code>D</code>, <code>C</code>, <code>B</code>, <code>A</code>—or, with my new group names: <code>SemTagContext</code>, <code>SemTag</code>, <code>ST</code>, <code>LT</code>?</p>
  
  <p><sub>Note: The data table above is shortened. The bar widths in the plot don't reflect this short data example, but the full dataset I have. The problem is the same though.</sub></p>