title: ggplot2: Keep x-axis labels in non-alphabetical order
body: <p>I'm using ggplot2 to plot the annual occurrence of events in states. I want the state labels to be in the same order as shown in the data table &quot;AZ CT NH NM DE...&quot; but ggplot automatically reorganizes the state labels in alphabetical order &quot;AZ CT DE NH...&quot;. I created groups so I could display ranges in &quot;num&quot; values (ex. NM and TN). Please ignore the group numbering--I took out some data points to make the table smaller.</p>
  <p><a href="https://i.stack.imgur.com/iPxRM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iPxRM.png" alt="enter image description here" /></a></p>
  <pre><code>ggplot(guidelines, aes(x = state, y = num, group = grp)) +
  geom_point() + geom_line(linetype = &quot;dotted&quot;) +
  labs(x = &quot;State&quot;, y = &quot;Number&quot;) + 
  labs(title = &quot;A&quot;) +
  scale_y_continuous(breaks = seq(0, 11, 1), 
                    limits=c(0,11))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/gCXHC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gCXHC.png" alt="enter image description here" /></a></p>
  <p>I have tried the suggestions of previous posts to use factor and levels like so:</p>
  <pre><code>guidelines$state &lt;- factor(guidelines$state, levels = unique(guidelines$state)
  </code></pre>
  <p>But it does not work because I am using groups and repeating state names. Any ideas on how to get around this?</p>