Tables - Time Series Stacked by Year
Stacks a single series of time series data by year, to facilitate year-on-year comparisons (e.g., seasonality, growth). This is different from stacking variables, which is accomplished by stacking data files.
How to Stack by Years
- Add the object:
- In Displayr: Insert > More > Tables > Stack Years
- In Q: Create > Tables > Stack Years
- Select the table that contains the date series to stack in Inputs > Data Table.
Example
The example table shows the before and after results of stacking the Wham_world variable into three years.
Options
The options in the Object Inspector are organized into two tabs: Inputs and Properties.
Inputs
Data table The table of data to be stacked.
Number of years The number of years to show as rows (columns) in the final table.
Calendar years If selected, years refer to the actual year. Otherwise, they refer to the 12 months up until the most recent date.
Period number If selected, period numbers rather than dates (of the final year) are shown.
Switch rows and columns Transposes the output table.
Properties
This tab contains options for formatting the size of the object, as well as the underlying R code used to create the visualization, and the JavaScript code use to customize the Object Inspector itself (see Object Inspector for more details about these options). Additional options are available by editing the code.
See Also
Technical details
Years can have uneven numbers of periods.
Code
var heading_text = "Stack Years";
if (!!form.setObjectInspectorTitle)
form.setObjectInspectorTitle(heading_text, heading_text);
else
form.setHeading(heading_text);
form.dropBox({label: "Data table",
types:["table", "RItem"],
name: "formTable"});
form.numericUpDown({label: "Number of years",
default_value: 2,
minimum: 2,
maximum: Number.MAX_SAFE_INTEGER,
name: "formYears"})
form.checkBox({label: "Calendar years",
default_value: true,
name: "formCalendar", prompt: "Actual year instead of most recent 12 months"})
form.checkBox({label: "Period number",
default_value: false,
name: "formPeriodNumber", prompt: "Show period number instead of actual date"})
form.checkBox({label: "Switch rows and columns",
default_value: false,
name: "formTranspose"})
stacked.years <- flipTables::StackYears(formTable, n.years = formYears, calendar = formCalendar, period.number = formPeriodNumber, transpose = formTranspose)