Legend Order

17 views
Skip to first unread message

Nick S

unread,
Feb 4, 2010, 8:45:06 PM2/4/10
to ggplot2
What is the best way to adjust the legend so that it matches the order
in which factors are plotted?

Example output can be found here (http://ggplot2.googlegroups.com/web/
Ex_Legend.jpg). The legend order is not the same as the plotting
order. I imagined this has to have been asked before but could not dig
up any relavent info in my search.

Thanks in advance for any help!

Nick S

unread,
Feb 4, 2010, 8:48:25 PM2/4/10
to ggplot2

James Howison

unread,
Feb 4, 2010, 10:28:29 PM2/4/10
to ggplot2

Is the ordering you want fixed, or do you want to order it according to something like the average value of the time-series?

In general the order in the legend follows the order of the levels in the factor. Try something like

data$condition <- as.factor(data$condition, levels=c("4.5mg","6.0mg ACN",...) #... meaning so on for the order you want the Legend.

But it would be easier to help if you provided a complete (ie runnable), minimal example....

On Feb 4, 2010, at 20:48, Nick S wrote:

> Working link:
> http://ggplot2.googlegroups.com/web/Ex_Legend.jpg?gda=sAOd4j8AAADSH7y5MFnpO4_MGPipxqBFxKxIOJgjNR0ji7ijntej_ZUPkMQOff0KZyrTJ9_hi02ccyFKn-rNKC-d1pM_IdV0
>
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages