##
## Basic Fan
##
# empty plot
plot(NULL, xlim = c(1, 945), ylim = range(th.mcmc)*0.85)
# add fan
fan(th.mcmc)
##
## 20 or so examples of fan charts and
## spaghetti plots based on the th.mcmc object
##
## Make sure you have zoo, tsbugs, RColorBrewer and
## colorspace packages installed
##
demo("sv_fan", "fanplot")
##
## Fans for forecasted values
##
#create time series
net <- ts(ips$net, start=1975)
# fit model
library("forecast")
m <- auto.arima(net)
# simulate future values
mm <- matrix(NA, nrow=1000, ncol=5)
for(i in 1:1000)
mm[i,] <- simulate(m, nsim=5)
# interval fan chart
plot(net, xlim=c(1975,2020), ylim=c(-100,300))
fan(mm, type="interval", start=2013)
# anchor fan chart
plot(net, xlim=c(1975,2020), ylim=c(-100,300))
fan(mm, type="interval", start=2013,
anchor=net[time(net)==2012])
##
## Box Plots
##
# sample every 21st date of theta_t
th.mcmc21 <- th.mcmc[, seq(1, 945, 21)]
plot(NULL, xlim = c(1, 945), ylim = range(th.mcmc21))
fan(th.mcmc21, style = "boxplot", frequency = 1/21)
# additional arguments for boxplot
plot(NULL, xlim = c(1, 945), ylim = range(th.mcmc21))
fan(th.mcmc21, style = "boxplot", frequency = 1/21,
outline = FALSE, col = "red", notch = TRUE)
##
## Fan Boxes
##
plot(NULL, xlim = c(1, 945), ylim = range(th.mcmc21))
fan(th.mcmc21, style = "boxfan", type = "interval", frequency = 1/21)
# more space between boxes
plot(NULL, xlim = c(1, 945), ylim = range(th.mcmc21))
fan(th.mcmc21, style = "boxfan", type = "interval",
frequency = 1/21, space = 10)
# overlay spaghetti
fan(th.mcmc21, style = "spaghetti",
frequency = 1/21, n.spag = 50, ln.col = "red", alpha=0.2)
Run the code above in your browser using DataLab