Plot order (what steps on what)

179 views
Skip to first unread message

Stavros Macrakis

unread,
May 14, 2009, 12:43:01 PM5/14/09
to ggplot2, hadley wickham
If I'm not mistaken, ggplot plots geoms specified later in a plot spec
after, and on top of, geoms specified earlier.

Thus, + geom_line(...) + geom_point(...) plots the points on top of
the lines, and + geom_point(...) + geom_line(...) plots the lines on
top of the points. So I can control this by reordering the clauses.

How do I control the ordering within the geom? It appears that
geom_point plots left-to-right, bottom-to-top, but what I would like
to do is to specify which values plot on top of which others. The
typical case is that I have a scatterplot where I'm using color for
the third dimension, but in places where the dots are dense, I can't
see the rare case that I'm trying to pick out with color. I suppose I
could divide the data into multiple classes, and do something like

+ geom_point( data = df[df$z<1,], ...) + geom_point (data =
df[df$z >= 1 | df$z < 2, ], ...) + ...

but that is obviously pretty messy.

Is there some way to control this with a z-variable? What controls
the current ordering? Is it in a modifiable position_ clause or
something?

Thanks,

-s

hadley wickham

unread,
May 14, 2009, 12:53:47 PM5/14/09
to macr...@alum.mit.edu, ggplot2

You can use the order aesthetic. I haven't publicised it because it's
a bit buggy, but I'm pretty sure it works (at least) for points and
lines.

Hadley

--
http://had.co.nz/

Stavros Macrakis

unread,
May 14, 2009, 6:24:33 PM5/14/09
to hadley wickham, ggplot2
Beautiful!  Thank you.

            -s
Reply all
Reply to author
Forward
0 new messages