Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. # # convenience package...
  2. # central vs. decentralized production discussion
  3. # not part of this.
  4.  
  5. # minimal introduction to R
  6. # different editors and an interpreter
  7. # How-to-R Studio
  8. # # 4 Panes
  9. # # the ctrl+1 ctrl+2 shortcut
  10. # # don't store
  11. # # sign out button
  12. # # the local folder
  13. # # libraries aka package, system and local
  14. # # mounted folders
  15. # # how to get help ?initDefaultTheme vignette("tstools")
  16.  
  17. # # finding stuff: another tutorial -- sneak preview at the end of this
  18.  
  19.  
  20.  
  21. library(tstools)
  22.  
  23. # example 1: Basic use - input: a standard ts object
  24. # generating dummy data
  25. data(KOF)
  26. short <- window(KOF$kofbarometer,start=c(2007,1),end=c(2014,1))
  27.  
  28. tsplot(short,auto_legend=F)
  29.  
  30. # example 2: a list of ts objects
  31. ts1 <- ts(runif(40,-10,40),start=c(1995,1),freq=4)
  32. ts2 <- ts(runif(80,0,50),start=c(2000,1),freq=12)
  33.  
  34. tslist <- list()
  35. tslist$ts1 <- ts1
  36. tslist$ts2 <- ts2
  37.  
  38.  
  39. tsplot(ts1,ts2)
  40. tsplot(tslist)
  41.  
  42.  
  43. # stacked bar charts
  44. tsb1 <- ts(runif(30,-30,20),start=c(2010,1),frequency = 4)
  45. tsb2 <- ts(runif(30,0,50),start=c(2010,1),frequency = 4)
  46. tsb3 <- ts(runif(30,0,50),start=c(2010,1),frequency = 4)
  47. tsplot(tsb1,tsb2,tsb3,left_as_bar = T,
  48. manual_value_ticks_l = seq(-40,100,by=20),auto_legend=F)
  49.  
  50. # multiple y-axes
  51. data(KOF)
  52. tsplot(KOF$kofbarometer,
  53. tsr = KOF$reference,auto_legend=F)
  54.  
  55.  
  56. # multiple y-axes and different chart types
  57. tsb1 <- ts(runif(30,-30,20),start=c(2010,1),frequency = 4)
  58. tsb2 <- ts(runif(30,0,50),start=c(2010,1),frequency = 4)
  59. tsb3 <- ts(runif(30,0,50),start=c(2010,1),frequency = 4)
  60. tsb4 <- ts(runif(30,0,50),start=c(2010,1),frequency = 4)
  61. ll <- list(t1 = tsb1, t2 = tsb2, t3 = tsb3)
  62. llr <- list(t4 = tsb4)
  63.  
  64. tsplot(ll,tsr = llr,
  65. plot_title = "random stuff",
  66. plot_subtitle = "testing tstools",
  67. #plot_subtitle_r = "right tstools (%)",
  68. left_as_bar = T,
  69. manual_value_ticks_l = seq(-60,100,by=20),
  70. manual_value_ticks_r = seq(-20,140,by=20)
  71. )
  72.  
  73.  
  74. # subtitles to label axes
  75. tsplot(ll,tsr = llr,
  76. plot_title = "random stuff",
  77. plot_subtitle = "some index",
  78. plot_subtitle_r = "right tstools (%)",
  79. left_as_bar = T,
  80. manual_value_ticks_l = seq(-40,100,by=20),
  81. manual_value_ticks_r = seq(0,140,by=20)
  82. )
  83.  
  84. # tweaking themes
  85.  
  86. # # add hightlight window
  87. tt <- initDefaultTheme()
  88. tt$highlight_window <- T
  89. tt$highlight_window_start <- c(2014,1)
  90. tt$highlight_window_end <- c(2018,1)
  91. tsplot(tsb1,tsb2,tsb3,
  92. manual_value_ticks_l = seq(-40,80, by = 20),
  93. theme = tt)
  94.  
  95.  
  96. # add text or additional layers currently not possible because
  97. # cause of issues with legend positioning -- will be fixed soon.
  98.  
  99.  
  100. # export to xlsx
  101.  
  102. data(KOF)
  103. exportTsList(KOF,
  104. fname = "test",
  105. xlsx = T,
  106. meta_header = c("the world famous KOF Baro","the not-so famous reference"))
  107.  
  108.  
  109.  
  110. # submit issues: github.com/mbannert/tstools
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement