hadley/ggplot2 — Issue #406: order by factor with geom_pointrange and position_dodge
Author: rma
Created: 2012-02-14 17:11:19+00:00
State: open

In the following code, changing the order ("as.numeric(z)" or "- as.numeric(z)") has no effect (ggplot2 0.9.0, R 2.14.1, Debian Testing). I want to change the order so that when the coordinates are flipped, the order in the legend matches the ordering of the lines.

x <- c(1,2,3,1,2,3,1,2,3)
y <- c(0.1,0.2,0.3,0.12,0.22,0.32,0.14,0.24,0.34)
z <- c("a", "a", "a", "b", "b", "b", "c", "c", "c")
z <- factor(z, ordered=TRUE)

qplot(x, y, ymin=y-0.05, ymax=y+0.05, colour=z, order=-as.numeric(z),
geom="pointrange",
position=position_dodge(width=0.2, height=0)) + coord_flip()