Skip to content
Back to formatted view

Raw Message

Message-ID: <20090331220143.GA26441@psych.upenn.edu>
Date: 2009-03-31T22:01:43Z
From: Marianne Promberger
Subject: ggplot: order of numeric factor levels?

Hi,

I'm having problems with qplot and the order of numeric factor levels.

Factors with numeric levels show up in the order in which they appear
in the data, not in the order of the levels (as far as I understand
factors!)

Here is a minimal example:

library(ggplot2)
y <- c(-1,2,0,0,-2,-1)
z <- factor(y,levels=c(-2,-1,0,1,2))
qplot(z)

For me, the resulting plot is ordered: -1,2,0,-2

By contrast, 
plot(z) is neatly ordered -2,-1,0,1,2

What am I not getting?

Thanks for any pointers,

Marianne