Controlling ggplot2 legend display order

In 0.9.1, the rule for determining the order of the legends is secret and unpredictable. Now, in 0.9.2, dev version in github, you can use the parameter for setting the order of legend.

Here is the example:

plot <- ggplot(diamond.data, aes(carat, price, colour = clarity, shape = cut)) +
  geom_point() + opts(legend.position = "top")

plot + guides(colour = guide_legend(order = 1), 
              shape = guide_legend(order = 2))

enter image description here

plot + guides(colour = guide_legend(order = 2), 
              shape = guide_legend(order = 1))

enter image description here


It seems to me that the order of the legend is determined by the number of characters in the scale names. (Yes, I agree, that seems bizarre.)

So, a workaround is to pad your labels with spaces:

plot + labs(colour = "Clarity", shape = "      Cut")

enter image description here


I sincerely hope somebody posts a proper solution soon!