3

I have a ggplot with two legends, how can I rearrange the order of the legends of this plot, so that Sample Size appears below Party?

The docs show how to do this for a qplot, but I can't make the leap from that to the code I have.

Also didn't find here.

43Tesseracts
  • 4,617
  • 8
  • 48
  • 94
  • It is here: http://stackoverflow.com/questions/13143894/how-do-i-position-two-legends-independently-in-ggplot – Chris Oct 11 '15 at 06:32

1 Answers1

6

Just add guides(size = guide_legend(order = 1)) to your plot. It works by specifying the position size should take.

Further information you will find when you read the documentation for guides and guide_legend.

Slightly adapted example from ?guide_legend:

df <- data.frame(x = 1:20, y = 1:20, color = letters[1:5], size = LETTERS[1:2])
p <- ggplot(df, aes(x, y)) +
  geom_point(aes(colour = color, size = size))
p

p + guides(size = guide_legend(order = 1))

Thomas K
  • 3,242
  • 15
  • 29