I had a small problem which I was trying to solve for hours. I am trying to combine 2 plots together on the same continous x-axis scale by using 2 different sets of data train_series & test_series as shown below. I believe another way to do this is to shift the test_series data points 40 along the x-axis but I am unsure of how to do so.
Will appreciate any workarounds. Was searching through stack and the R plot documentation but couldn't find anything helpful. Any help or guidance is greatly appreciated, thanks!
set.seed(250)
timeseries=arima.sim(list(order = c(1,1,2), ma=c(0.32,0.47), ar=0.8), n = 50) 20 # Simulated data n=50
## partition into train and test
train_series=timeseries[1:40]
test_series=timeseries[41:50]
What I want is to combine the train_series & test_series on a continuous plot (ignore the 3 colored lines).
However, this is best I can do (see below).
plot(train_series, type="o", xlim=c(0, 50), ylim=c(0,50))
CodePudding user response:
You should start your x-axis at 41:
plot(train_series, type="o", xlim=c(0, length(c(train_series,test_series))), ylim=c(0,max(c(train_series,test_series))))
points(x = seq(from = 41, length.out = length(test_series)), y =test_series , pch = 19)