# aspect ratio for time series knitr::opts_chunk$set(fig.width = 9, fig.height = 5.5, out.width='5.2in', fig.align = 'center') library(x13story) # also loads seasonal
m <- seas(AirPassengers) x13page(m, "main")
This is a template for X-13 stories, descriptions of seasonal adjustment discussions that can be turned into PDFs or into interactive stories. For a more extensive description of the approach, see the vignette.
Use h2
header (##
) as top headers, so you can wrap several stories in a
book, separating them with h1
headers (#
).
To initiate a new page in an interactive story, use x13page()
. The function
takes an object of class "seas"
as its first argment, and a chararacter string
describing the series shown on the page as its second. For a list of all
available series, see the series
function from the seasonal package.
Everything you write after a call to x13page()
will appeare on that page. To start a new page, simply invoke x13page()
again.
x13page(m, "main", pdf = FALSE)
By default x13page()
will also inlclude a plot into a PDF, but this can be
changed by setting pdf = FALSE
. If you want to include a customized graph in
a PDF, the prettify()
function allows you to give seasonal and R base plots a
look that works well with the document template. Note that this plot will not
appear in an interactive story:
prettify(plot(final(m), main = "", xlab = "", ylab = "Passengers, in 1000"))
library(x13story) myseries <- structure(c(112, 118, 132, 129, 121, 135, 148, 148, 136, 119, 55, 55, 55, 55, 55, 135, 125, 149, 170, 170, 158, 133, 114, 140, 145, 150, 178, 163, 172, 178, 199, 199, 184, 162, 146, 166, 171, 180, 193, 181, 183, 218, 230, 242, 209, 191, 172, 194, 196, 196, 236, 235, 229, 88, 264, 272, 237, 211, 180, 201, 204, 188, 235, 227, 234, 264, 302, 293, 259, 229, 203, 229, 242, 233, 267, 269, 270, 315, 364, 347, 312, 274, 237, 278, 284, 277, 317, 313, 318, 374, 413, 405, 355, 306, 271, 306, 315, 301, 356, 348, 355, 422, 465, 467, 404, 347, 305, 336, 340, 318, 362, 348, 363, 435, 491, 505, 404, 359, 310, 337, 360, 342, 406, 396, 420, 472, 548, 559, 463, 407, 362, 405, 417, 391, 419, 461, 472, 535, 622, 606, 508, 461, 390, 432), .Tsp = c(1949, 1960.91666666667, 12), class = "ts") m <- seas(myseries, x11 = "") # initializes a second X-13 view x13page(m, 'x11.seasonal')
You can use arbitrary code in your document. Note that evaluations of R code are not shown in interactive stories.
dput(AirPassengers)
You can also use \LaTeX-style math both for PDFs and and the interactive view:
$$X_t = T_t + S_t + I_t$$
Inlined math, $E = mc^2$, is possible as well.
You can include your own data into the code. Use dput
to transform an existing series in your workspace into R code:
prettify(qqnorm(resid(m), main = "", xlab = ""))
This is still a bit experimental and subject to further changes.
You can add tables using the standard R Markdown syntax. The xtable
function
allows you to produce a nice PDF table. The following produces no output in
interactive stories, since we have the summary (and the X-13 output) available
all the time, so we can reference to them.
The data.frame
argument requires the latest dev Version of seasonal
, which
is not yet on CRAN.
# xtable with reasonable options (we may do this differently at some point) library(xtable) options(xtable.include.rownames = FALSE, xtable.booktabs = TRUE) m <- seas(x = AirPassengers, x11 = "") xtable(head(as.data.frame(m), 4), caption = 'Adjusted and unadjusted data.')
mstat <- formatC(1:10, width=2, flag="0") dta <- data.frame(Stat = paste0("M", mstat), Value = udg(m, paste0("f3.m", mstat))) xtable(dta, caption = 'X-11 M Statistics')
library(xtable) options(xtable.include.rownames = FALSE, xtable.booktabs = TRUE) xtable(as.data.frame(summary(m)), caption = 'Coefficient Overview')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.