0

I looked at Plot two graphs in same plot in R but did not figure it out.

trend.ts = ts(c(100,101,102))
plot(trend.ts)
season.ts = ts(c(3,4,5))
lines(season.ts)

Apparently lines does not draw the season.ts because it is outside of the left y axis.

How to draw it on the same graph on its own right y axis?

Is there some introductory documentation that shows this?

Community
  • 1
  • 1
B Seven
  • 39,557
  • 59
  • 208
  • 346
  • Yes, I did. Are you suggesting that one of the links that you found by Googling has a clear answer? – B Seven Jan 03 '16 at 19:03
  • @BSeven He even linked it for you – Alex W Jan 03 '16 at 19:14
  • 2
    Most certainly, yes. Try `par(mar = c(5, 4, 4, 4) + 0.3) ; plot(trend.ts) ; par(new = TRUE) ; plot(1:3, season.ts, type = "l", axes = FALSE, bty = "n", xlab = "", ylab = "") ; axis(side=4, at = pretty(range(season.ts))) ; mtext("season.ts", side=4, line=3)` Though you won't notice it because both of your series are identical while scaled. So maybe try this for `season.ts = ts(c(5,4,3))`. Anyway, I'm hammering this unless someone has any objections. – David Arenburg Jan 03 '16 at 19:16
  • @DavidArenburg - Thanks, your example worked. Why do you set these params `1:3, season.ts, type = "l", axes = FALSE, bty = "n", xlab = "", ylab = ""`? – B Seven Jan 03 '16 at 19:46
  • That will require a lot of explanations. Please read `?par` and `?xy.coords` especially after the "*If y is NULL and x is a*" part. – David Arenburg Jan 03 '16 at 20:38
  • @DavidArenburg - OK, thanks for the info. – B Seven Jan 03 '16 at 21:49

0 Answers0