I want to plot two vectors in a simple line plot and then want to add a line at the 0 x axe point.
This is how I tried to implement it:
sale <-
structure(c(-0.049668136, 0.023675638, -0.032249731, -0.071487224,
-0.034017265, -0.031278933, -0.052070721, -0.034305542, -0.019041209,
-0.050459175, -0.017315808, -0.012787003, -0.03341208, -0.045078144,
-0.036638132, -0.036533367, -0.012683656, -0.014388251, -0.006775188,
-0.037153807, -0.008941402, -0.011760677, -0.005077979, -0.041187417,
-0.001966554, -0.028822067, 0.021828558, 0.016208791, -0.026897492,
-0.032107207, -0.008496522, -0.028027096, -0.013746662, -0.004545603,
-0.005679941, -0.004614187, 0.004083014, -0.012624954, -0.016362079,
-0.006350167, -0.019551277), na.action = structure(42:45, class = "omit"))
purchase <-
structure(c(0.042141187, 0.075875128, 0.090953485, 0.050951625,
0.082566915, 0.184396833, 0.136625887, 0.042725409, 0.135028692,
0.13201904, 0.093634104, 0.16776844, 0.13645719, 0.201365036,
0.227589832, 0.236473792, 0.269064385, 0.200981722, 0.144739536,
0.145256493, 0.040205545, 0.031577107, 0.014767345, 0.005843065,
0.034805051, 0.082493053, 0.010572227, 0.000645763, 0.033368236,
0.024326153, 0.038601182, 0.025446045, 0.000556418, 0.017201608,
0.008316872, 0.059722053, 0.059695415, 0.076940829, 0.067650014,
0.002029566, 0.008466334), na.action = structure(42:45, class = "omit"))
timeLine <- c(-20:+20)
plot(sale,type="b", xlim=timeLine)
Error in plot.window(...) : invalid 'xlim' value
par(new=T)
plot(purchase,type="b", xlim=timeLine)
Error in plot.window(...) : invalid 'xlim' value
par(new=F)
However I get Error in plot.window(...) : invalid 'xlim' value
. Why is my timeLine false implemented?
I really appreciate your answer!
The vector supplied to 'xlim' needs to only have two elements c(max,min)
. Try this:
timeLine <- c(-20 , +20)
plot(sale, type="b", xlim=timeLine)
Then to plot a second item you should use lines (and you should not try to re-specify xlim:
lines( purchase, type="b")
Except then you discover that the ylimits were not set and the range of values in 'purchase' are not overlapping with those of 'sale', so you need to set the ylimits in hte first plot cal:
plot(sale,type="b", xlim=timeLine, ylim=c(-.1,.4) )
lines( purchase, type="b")
This would all have been handled more simply with just this:
matplot( cbind( sale, purchase), type="b")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With