How to reorder the items in a legend?
<p>I'm trying to change the order in which legend items appear.  I've spent about an hour at this, with no results.</p>

<p>Here's an example setup:</p>

<pre><code>library(ggplot2)
set.seed(0)
d &lt;- data.frame(x = runif(3), y = runif(3), a = c('1', '3', '10'))
</code></pre>

<p>And here's one of the many things I've tried:</p>

<pre><code>ggplot(d, aes(x = x, y = y)) + 
    geom_point(size=7, aes(color = a, order = as.numeric(a)))
</code></pre>

<p><a href="https://i.stack.imgur.com/Nzc1B.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Nzc1B.png" alt="enter image description here"></a></p>

<p>(My naive hope, of course, was that the legend items would be shown in the numeric order: 1, 3, 10.)</p>