Learn R Programming

{tstools} – a Time Series Toolbox for Official Statistics

Plot official statistics’ time series conveniently: automatic legends, highlight windows, stacked bar chars with positive and negative contributions, sum-as-line option, two y-axes with automatic horizontal grids that fit both axes and other popular chart types. ‘tstools’ comes with a plethora of defaults to let you plot without setting an abundance of parameters first, but gives you the flexibility to tweak the defaults. In addition to charts, ‘tstools’ provides a super fast, ‘data.table’ backed time series I/O that allows the user to export / import long format, wide format and transposed wide format data to various file types.

-> pkgdown documentation <-

Installation

You can install the development version of tstools from GitHub with:

# install.packages("remotes")
remotes::install_github("kof-ch/tstools")

Example Use: Time Series Charts with Legends by Default

{tstools} lets you draw time series line charts that come with a legend out-of-the-box. Simply feed the tsplot() function with a list of time series.

library(tstools)
## basic example code
tsl <- list(
  AirPassengers = AirPassengers,
  JohnsonJohnson = JohnsonJohnson
)

tsplot(tsl)

and use easily use 2 y-axis. (I know some argue those double axes are fundamentally flawed, but my peers didn’t care and asked for it.)

tsplot(
  "Air Passengers" = tsl$AirPassengers,
  tsr = list("Johnson & Johnson" = tsl$JohnsonJohnson)
)

Copy Link

Version

Install

install.packages('tstools')

Monthly Downloads

410

Version

0.4.3

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Stéphane Bisinger

Last Published

January 18th, 2024

Functions in tstools (0.4.3)

tsplot

Plot Time Series
m_to_q

Turn monthly series with regular NAs to quarter
resolve_ts_overlap

Concatenate Time Series and Resolve Overlap Automatically
set_month_to_NA

Set Periods to NA
tstools-deprecated

Deprecated function(s) in tstools
read_swissdata_meta

Read swissdata style yaml timeseries metadata
strip_ts_of_leading_nas

Strip Leading / Trailing NAs from a Time Series Object
wide_to_ts

Transform a wide format data.frame into a tslist
tsqm

Interpolate quarterly time series into monthly
start_ts_after_internal_nas

Start a Time Series after the Last Internal NA
read_ts

Import time series data from a file.
write_ts

Export a list of time series to a file.
regularize

Turn an Irregular Time Series to a Regular, ts-Based Series
KOF

KOF Barometer - Swiss Business Cycle Indicator
get_date_vector

Compute the Period Vector representation of a Decimal Time value
color_blind

Provide Colorblind Compliant Colors
compute_decimal_time

Compute Decimal Time from a ts Period Vector
CHGDP

CH GDP Growth Contributions
fill_year_with_nas

Fill Up a Time Series with NAs
.read_swissdata_meta_unknown_format

Read Meta Data File w/o File Extension
concat_ts

Concatenate to Non-Overlapping Time Series
create_cross_sec_overview

Create an Overview data.table of (last) observations
getCiLegendColors

Helper to calculate ci colors for legends
generate_random_ts

Generate a list of random time series
init_tsplot_theme

Initiate Default Theme
overlap_sorted_ts_lists

Concat Time Series list wise
df_to_reg_ts

Turn data.frame to Regular Monthly or Quarterly Time Series
create_dummy_ts

Flexible Function to Create Time Series Dummy Variables
overlap_ts_lists_by_name

Resolve Overlap Listwise, helpful with SA
long_to_ts

Transform a long format data.frame of time series to a tslist
read_swissdata

Read data generated by the Swissdata project