The order that geom_line() connects points.

5,236 views
Skip to first unread message

Sam Albers

unread,
Jul 26, 2011, 12:36:22 PM7/26/11
to ggplot2
Hello fellow ggplot-ters,

I have a question about how ggplot2 draws lines. I am attempting to
draw a plot with as a depth profile with lines connecting the points.
The problem I am running into, is that ggplot2 traces the line
according to the x-axis so that the line moves up and down between
different depths. What I would like is the line to move from the
shallowest depth to the deepest depth in that order. The following
should illustrate my problem:

library(ggplot2)
egavg <- read.csv("http://dl.dropbox.com/u/1574243/eg_data.csv",
header=TRUE, sep=",")

ggplot(egavg, aes(x=temp, y=depth.cat)) +
geom_line(aes(colour=site)) +
geom_point(aes(group=site, colour=site, shape=site)) +
scale_y_reverse()

The problem is particularly apparent with "Station 3". Is this
possible in ggplot2? Can anyone suggest a way to do this?

Thanks so much in advance!

Sam

Kohske Takahashi

unread,
Jul 26, 2011, 12:49:47 PM7/26/11
to Sam Albers, ggplot2
hi,

use geom_path instead of geom_line:

ggplot(egavg, aes(x=temp, y=depth.cat)) +
geom_path(aes(colour=site)) +


geom_point(aes(group=site, colour=site, shape=site)) +
scale_y_reverse()

--
Kohske Takahashi <takahash...@gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

Sam Albers

unread,
Jul 26, 2011, 12:53:18 PM7/26/11
to Kohske Takahashi, ggplot2
Brilliant! Thanks so much.
Reply all
Reply to author
Forward
0 new messages