Skip to content

Instantly share code, notes, and snippets.

@mbannert
Created June 7, 2017 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbannert/fa0806946509a53a55e5eef87c297473 to your computer and use it in GitHub Desktop.
Save mbannert/fa0806946509a53a55e5eef87c297473 to your computer and use it in GitHub Desktop.
# # convenience package...
# central vs. decentralized production discussion
# not part of this.
# minimal introduction to R
# different editors and an interpreter
# How-to-R Studio
# # 4 Panes
# # the ctrl+1 ctrl+2 shortcut
# # don't store
# # sign out button
# # the local folder
# # libraries aka package, system and local
# # mounted folders
# # how to get help ?initDefaultTheme vignette("tstools")
# # finding stuff: another tutorial -- sneak preview at the end of this
library(tstools)
# example 1: Basic use - input: a standard ts object
# generating dummy data
data(KOF)
short <- window(KOF$kofbarometer,start=c(2007,1),end=c(2014,1))
tsplot(short,auto_legend=F)
# example 2: a list of ts objects
ts1 <- ts(runif(40,-10,40),start=c(1995,1),freq=4)
ts2 <- ts(runif(80,0,50),start=c(2000,1),freq=12)
tslist <- list()
tslist$ts1 <- ts1
tslist$ts2 <- ts2
tsplot(ts1,ts2)
tsplot(tslist)
# stacked bar charts
tsb1 <- ts(runif(30,-30,20),start=c(2010,1),frequency = 4)
tsb2 <- ts(runif(30,0,50),start=c(2010,1),frequency = 4)
tsb3 <- ts(runif(30,0,50),start=c(2010,1),frequency = 4)
tsplot(tsb1,tsb2,tsb3,left_as_bar = T,
manual_value_ticks_l = seq(-40,100,by=20),auto_legend=F)
# multiple y-axes
data(KOF)
tsplot(KOF$kofbarometer,
tsr = KOF$reference,auto_legend=F)
# multiple y-axes and different chart types
tsb1 <- ts(runif(30,-30,20),start=c(2010,1),frequency = 4)
tsb2 <- ts(runif(30,0,50),start=c(2010,1),frequency = 4)
tsb3 <- ts(runif(30,0,50),start=c(2010,1),frequency = 4)
tsb4 <- ts(runif(30,0,50),start=c(2010,1),frequency = 4)
ll <- list(t1 = tsb1, t2 = tsb2, t3 = tsb3)
llr <- list(t4 = tsb4)
tsplot(ll,tsr = llr,
plot_title = "random stuff",
plot_subtitle = "testing tstools",
#plot_subtitle_r = "right tstools (%)",
left_as_bar = T,
manual_value_ticks_l = seq(-60,100,by=20),
manual_value_ticks_r = seq(-20,140,by=20)
)
# subtitles to label axes
tsplot(ll,tsr = llr,
plot_title = "random stuff",
plot_subtitle = "some index",
plot_subtitle_r = "right tstools (%)",
left_as_bar = T,
manual_value_ticks_l = seq(-40,100,by=20),
manual_value_ticks_r = seq(0,140,by=20)
)
# tweaking themes
# # add hightlight window
tt <- initDefaultTheme()
tt$highlight_window <- T
tt$highlight_window_start <- c(2014,1)
tt$highlight_window_end <- c(2018,1)
tsplot(tsb1,tsb2,tsb3,
manual_value_ticks_l = seq(-40,80, by = 20),
theme = tt)
# add text or additional layers currently not possible because
# cause of issues with legend positioning -- will be fixed soon.
# export to xlsx
data(KOF)
exportTsList(KOF,
fname = "test",
xlsx = T,
meta_header = c("the world famous KOF Baro","the not-so famous reference"))
# submit issues: github.com/mbannert/tstools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment