0

I used par() to combine the graph, but it is not working

d1=decompose(abuja)
d2=decompose(ilorin)
d3=decompose(jos)
d4=decompose(lafia)
d5=decompose(lokoja)
d6=decompose(makurdi)
d7=decompose(minna)

par(mfrow=c(7,1))
plot(d1)
plot(d2)
plot(d3)
plot(d4)
plot(d5)
plot(d6)
plot(d7)

After doing this, it did not work.

1 Answer 1

0

Welcome to SO! par() won't work because plot.decomposed.ts() (which you implicitly call when calling plot()) isn't designed to work that way. The most straightforward alternative is to use autoplot() from the forecast package to generate decomposition plots and combine them using patchwork.

Here is an example.

m1 = decompose(co2)
m2 = decompose(AirPassengers)
m3 = decompose(UKgas)
p1 = autoplot(m1)
p2 = autoplot(m2)
p3 = autoplot(m3)
p1 / p2 / p3

The last line, p1 / p2 / p3, tells R to stack them vertically. If you want to stack them horizontally, use p1 + p2 + p3. If you're being feisty, you can also try (p1 + p2)/p3 to stack the first two horizontally and the last one beneath it.

stacked vertically stacked horizontally stacked crazily

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.