The idea is to use a group. To do this, you need to add a third column that you can use to group. A possible way to achieve this is as follows.
First I define data samples
df <- read.table(text = "XY 100 50 80 60 70 90 110 60 30 20", header = TRUE)
Then I create a new data frame where the first row is repeated for each of the other rows. A grp column is grp that associates each repetition of the first row with one of the other rows:
n <- nrow(df) - 1 new_data <- data.frame(X = c(rep(df$X[1], n), df$X[-1]), Y = c(rep(df$Y[1], n), df$Y[-1])) new_data$grp <- as.factor(rep(1:n, times = 2)) new_data
Now the chart can be created directly using ggplot:
library(ggplot2) ggplot(new_data, aes(X, Y, group = grp)) + geom_point() + geom_line()

An aesthetic group controls which points should be connected by a line. Since the grp column in new_data always combines the repetition of the first row with each of the other rows, the point corresponding to the first row is associated with each of the other points.
If you omit group = grp , a graph is drawn with one line going through all the points.
Stibu source share