On 30/06/18 01:41, Jérôme François via R-help wrote:
Dear members,

I would like to plot a second time series (a forecast) to a seasonal plot made 
with function seasonplot() from the package forecast.


Here is a reproducible example:
ts1 <- structure(c(112035, 111182, 111015, 109331, 107525, 107749, 111435,
111629, 112462, 112256, 109496, 107917, 108221, 107463, 105960,
103883, 101038, 100056, 101628, 102973, 103371, 102463, 100774,
100718, 100471, 99828, 99365, 98521, 95695, 96443, 96287, 97525,
98293, 98014, 96658, 96736, 96089, 95337, 95382, 92748, 91448,
91560, 92996, 94046, 94128, 93888, 93888, 91091, 91877, 91681,
91045, 89367, 87912), .Tsp = c(2014, 2018.33333333333, 12), class = "ts")

ts2 <- structure(c(87867.2152330971, 89713.0862474283, 89600.565347383,
91066.3196835822, 90523.1926861474, 89322.8025396445, 88771.5545520503,
89247.0913151542, 88803.5578121458, 88060.0948570082, 87015.6578227365,
85785.4121532206), .Tsp = c(2018.41666666667, 2019.33333333333,
12), class = "ts")


library(forecast)seasonplot(ts1, year.labels = TRUE, year.labels.left = TRUE)


How can I add ts2 to the seasonal plot? I would like it to be distinguishable 
from ts1 (e.g. different color).

lines(ts2) doesn't work.
Thank you.


I don't know anything about forecast/seasonplot. However my experience is that par(new=TRUE) usually rescues one in situations like this.

It's a bit shaganappi, but ...

seasonplot(ts1, year.labels = TRUE, year.labels.left = TRUE,
           main="Whatever")
OP <- par(new=TRUE,xaxt="n",yaxt="n")
seasonplot(ts2, col="red",main="")
par(OP)

seems to work.

It would be nice to have an "add=" argument (defaulting to FALSE, of course) to seasonplot().

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to