How to super impose a new line to existing plot

Viewed 33

Let say I have this data

x = 1:10
y = 21:30
x1 = seq(x[1], tail(x, 1), length.out = 100)
y1 = rep(25, length(x1))
plot(x, y, col = "red")
plot(x1, y1, type = "l", col = "green")

Now I want to super impose the second plot onto the first plot. Note that the x values are not same, although maximum and minimum values are exactly same.

Is there any way to achieve this?

Thanks for your time.

1 Answers

Change the last line of code into:

lines(x1, y1, type = "l", col = "green")

Code:

x = 1:10
y = 21:30
x1 = seq(x[1], tail(x, 1), length.out = 100)
y1 = rep(25, length(x1))
plot(x, y, col = "red")
lines(x1, y1, type = "l", col = "green")

enter image description here

Related