2
votes

I want to create a ggplot with two short time series against each other.

Bild <- read.table(textConnection("time variable density
late A 0.0013158160
late B 0.0006036366
early A 0.0014638489
early B 0.0016562259"), header = TRUE)

When I create a ggplot with geom_point() with

ggplot(data = Bild, aes(x = time, y = density, color = variable)) +
 geom_point()

I get a nice graph. But instead of two points for each time series, I want a line between them. So I try

ggplot(data = Bild, aes(x = time, y = density, color = variable)) +
 geom_line()

which doesn't work. Error messages says "geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?" - what's wrong?

1

1 Answers

1
votes

It's pretty much what the error message is saying. ggplot just needs to know which lines to connect. You should add a group= aesthetic

ggplot(data = Bild, aes(x = time, y = density, group=variable, color = variable)) +
geom_line()

enter image description here