Build two graphs on one graph. function lines do not work

I want to build two graphs on the same graph. I read this post , but the lines function does not work, nothing happens. I do not know what the problem is. Any ideas?

Change reproducible example:

 > tr_error [1] 0.2314984 0.2314990 0.2314981 0.2314955 0.2314955 0.2314943 0.2314912 [8] 0.2314924 > tst_error [1] 0.001461264 0.001461767 0.001461001 0.001459936 0.001459626 0.001458594 [7] 0.001457719 0.001458288 > plot(tst_error, type='l') > lines(tr_error, type='l', col='red') 

maybe there is a second plot, but is it higher?

+7
source share
1 answer

It doesn’t work, because the y-limits do not include the range of the second vector.

  plot(tst_error, type='l', ylim=range( c(tst_error, tr_error) ) ) lines(tr_error, type='l', col='red') 

This will not be a particularly interesting plot, since the scale of the two vectors is so different. The red line will look completely flat.

+11
source

All Articles