Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Combining continuous plots using 2 sets of data (R plot)

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).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

However, this is best I can do (see below).

plot(train_series, type="o", xlim=c(0, 50), ylim=c(0,50)) 

enter image description here

>Solution :

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)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading