[r] Combine Points with lines with ggplot2

I would like to plot a time series that look like this:

enter image description here

what I plot with:

qplot(Jahr, Wert, data=tu, group = Geschlecht, color = Altersgr) + facet_grid(Geschlecht ~ Land)

My data looks like this:

  Land   Altersgr Geschlecht Jahr  Wert
1   DE    < 20 J.          m 2000  13.0
2   DE  20-<65 J.          m 2000  25.7
3   DE     65+ J.          m 2000  70.1
4   DE  65-<80 J.          m 2000  44.2
5   DE     80+ J.          m 2000 213.5
6   BB    < 20 J.          m 2000  26.8

Everything is fine so far. But I have to connect the corresponding points (same color) with a line. I couldn't figure out how to do that. If I use geom_line() I got this result:

enter image description here

Which is not what I want... I just have the feeling I overlook something...

Any suggestions? Thanks for y'all help.

This question is related to r ggplot2

The answer is


The following example using the iris dataset works fine:

dat = melt(subset(iris, select = c("Sepal.Length","Sepal.Width", "Species")),
      id.vars = "Species")
ggplot(aes(x = 1:nrow(iris), y = value, color = variable), data = dat) +  
      geom_point() + geom_line()

enter image description here


A small change to Paul's code so that it doesn't return the error mentioned above.

dat = melt(subset(iris, select = c("Sepal.Length","Sepal.Width", "Species")),
           id.vars = "Species")
dat$x <- c(1:150, 1:150)
ggplot(aes(x = x, y = value, color = variable), data = dat) +  
  geom_point() + geom_line()