0

Suppose I have V1, V2 and V3, V4. V1 and V2 form a time series, and V3 and V4 form a time series. V1 and V3 are the time variables and V2 and V4 are the dependent variables of same units. V1 and V3 are periods that overlap eachother, but they don't start/end at the same points.

First I plotted V1 and V2 with, plot(V1,V2, type="l"). But how would I plot these 2 pairs of variables on the same axis? I would like to merge V1 and V2 together into a data table and do the same with V3 and V4, calling them D1 and D2 respectively. Then I can maybe use plot(D1,D2..), but I don't know how to merge variables like that.

Update:

V1= c(6,7,8,9,10,11,12,13,14,15,16,17,18)
V2= c(27,53,68,45,75,35,72,35,25,27,27,26,52)
V3= c(2,3,4,5,6)
V4=c(54,23,86,43,26)
plot(V1,V2, type="l")
  • Please provide sample data and sample code. (Read [help/mcve](http://stackoverflow.com/help/mcve) and [reproducible examples](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for reference, then edit your question.) – r2evans Jul 09 '16 at 09:26
  • duplicate of question here : http://stackoverflow.com/questions/2564258/plot-two-graphs-in-same-plot-in-r – Virag Swami Jul 09 '16 at 09:42

1 Answers1

0

Suppose I have V1, V2 and V3, V4. V1 and V2 form a time series, and V3 and V4 form a time series. V1 and V3 are the time variables and V2 and V4 are the dependent variables of same units. V1 and V3 are periods that overlap eachother, but they don't start/end at the same points. ... [H]ow would I plot these 2 pairs of variables on the same axis?

You can do

set.seed(1)
V1 <- 1:10
V2 <- runif(length(V1))
V3 <- 3:7
V4 <- runif(length(V3))
plot(V1, V2, type="l", xlim = range(c(V1, V3)), ylim = range(c(V2, V4)))
lines(V3, V4, lty = "dashed")
lukeA
  • 53,097
  • 5
  • 97
  • 100