Base R: add points() in a loop defined by group

#1
Dear all,

I am looking for a way to generate different plots in base R with adding points and lines manually to the plot. Here is my sample data:
Code:
xy <- data.frame(NAME=c("NAME1","NAME1","NAME2","NAME2"), X_START_YEAR=c(1984,1986,1899,1903), Y_START_VALUE=c(75,25,-90,-8),X_END_YEAR=c(1986,1994,1909,1924),Y_END_VALUE=c(20,50,-15,-70))
xy
      NAME          X_START_YEAR    Y_START_VALUE   X_END_YEAR   Y_END_VALUE
    1 NAME1         1984            75              1986          20
    2 NAME1         1986            25              1994          50
    3 NAME2         1899           -90              1909         -15
    4 NAME2         1903            -8              1924         -70

Is it possible to add points() to a plot with the values from the first row (STARTING POINT X_START_YEAR/Y_START VALUE to END POINT: X_END_YEAR/Y_END_VALUE) and then plot again in the same plot in the same scheme the values for the second row.

After this plot has been generated a new group defined by NAME starts and a new plot should be generated for rows 3 and 4 in the same scheme as above.

The goal in the end is to connect the points by a line using type=l.

Unlike in this sample data, I have about 40000 rows and 1300 groups in the end and I am looking for a way to correctly plot this data in base R. Any help is appreciated!

Kind regards,
redshoe
 
Last edited: