I am trying to change the display order of legend elements. I spent about an hour on this, with no results.
Here's an installation example:
library(ggplot2) set.seed(0) d <- data.frame(x = runif(3), y = runif(3), a = c('1', '3', '10'))
And here is one of the many things I've tried:
ggplot(d, aes(x = x, y = y)) + geom_point(size=7, aes(color = a, order = as.numeric(a)))

(My naive hope, of course, was that the elements of the legend would be shown in numerical order: 1, 3, 10.)
source share