require(dplyr)
require(gganimate)
library("gridExtra")
library(ggfortify)
require(anytime)
require(lubridate)
library(knitr)
require(hrbrthemes)
require(plotly)

get_serie<-function(time_serie,type){
  n=length(time_serie)
  date=c()
  if(type=="MONTHLY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "month")
    periodo=12
  }
  if(type=="YEARLY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "year")
    periodo=1
  }
  if(type=="QUARTELY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    start
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "quarter")
    periodo=4
  }

  seas<-matrix(time_serie, nrow = floor(length(time_serie)/periodo), byrow = T)
  means=c()
  for(i in 1:periodo){
    means<-c(means,mean(seas[,i]))[-13]
  }
  media=mean(means)
  means<-rep(means, periodo)
  seasonal<-means-media

  time=(1:length(time_serie))

  linear_reg<-lm(time_serie~time, time_serie)
  slope<-linear_reg$coefficients[2]
  inter<-linear_reg$coefficients[1]

  trend<-inter+ time*slope
  df<-data.frame(time_serie)
  df1<-data.frame(trend)
  time<-1:n


  random<-time_serie-seasonal-trend


  df<-data.frame(date, time_serie, seasonal,trend, random )
  return(df)
}



plot_serie<-function(time_serie, type, plot){
  date=c()
  if(type=="MONTHLY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "month")
  }
  if(type=="YEARLY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "year")
  }
  if(type=="QUARTELY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "quarter")
  }
  df<-data.frame(date, time_serie)
  g<-ggplot(df)+geom_line(aes(x=df$date, y=df$time_serie))+ geom_point(aes(x=df$date, y=df$time_serie))+labs(x="date", y="time serie")+ggtitle(paste("serie"))+ theme(legend.position="none")+transition_reveal(date)
  p <- df %>%
    ggplot( aes(x=date, y=time_serie)) +
    geom_area(fill="#69b3a2", alpha=0.5) +
    geom_line(color="#69b3a2") +
    ylab("time serie") +
    theme_ipsum()

  # Turn it interactive with ggplotly
  p <- ggplotly(p)
  if(plot=="ggplot"){return(g)}else{return(p)}



}


trend_sta<-function(time_serie){
  medias<-c()
  n<-length(time_serie)
  stp<-floor(n/11)
  for (i  in 1:floor(length(time_serie)/stp)) {
    medias[i]=mean(time_serie[(stp*(i-1)):(stp*i)]%>% t() %>% as.vector(), na.rm = 1)
  }
  f<-approxfun(x=seq(from=1, length.out = length(medias)+1, by=stp)[-(stp-1)], y=medias)
  m<-f(1:n)
  nuevo<-(time_serie-m)
  df<-data.frame(time_serie)
  df1<-data.frame(nuevo)
  time<-(1:n)

  linear_reg<-lm(time_serie~time, time_serie)
  slope<-linear_reg$coefficients[2]

  trend=""
  if(slope<0){trend= "negative trend"}else{trend="positive trend"}

  bxp<-ggplot(df, aes(time, time_serie)) + geom_line() + stat_smooth(method =lm)+ annotate("text", x = 17, y = max(time_serie)-max(time_serie)/30, label = paste("slope:", slope))+annotate("text", x = 15, y = max(time_serie)-max(time_serie)/10, label = paste(trend))+labs(x="date", y="time serie")+ggtitle(paste("trend serie"))+ theme(legend.position="none")

  dp<-ggplot(df1, aes(time, nuevo)) + geom_line()+labs(x="date", y="time serie")+ggtitle(paste("Not trend"))+ theme(legend.position="none")
  d<-ggplot(df1, aes(time, nuevo)) + geom_line()
  grid.arrange(bxp, dp, ncol = 1, nrow = 2)
}

season_time_serie<-function(time_serie, periodo, type, plot){
  date=c()
  if(type=="MONTHLY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "month")
  }
  if(type=="YEARLY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "year")
  }
  if(type=="QUARTELY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "quarter")
  }
  seas<-matrix(time_serie, nrow = length(time_serie)/periodo, byrow = T)
  means=c()
  for(i in 1:periodo){
    means<-c(means,mean(seas[,i]))[-13]
  }
  media=mean(means)
  means<-rep(means, periodo)
  obs<-means-media

  df1<-data.frame(date, obs)
  p <- df1 %>%
    ggplot( aes(x=date, y=obs)) +
    geom_area(fill="#69b3a2", alpha=0.5) +
    geom_line(color="#69b3a2") +
    ylab("seasonality") +
    theme_ipsum()

  # Turn it interactive with ggplotly
  p <- ggplotly(p)

  g<-ggplot(df1)+geom_line(aes(x=date, y=df1$obs, col="red"))+theme_grey()+labs(x="date", y="time serie")+ggtitle(paste("serie"))+ theme(legend.position="none")
  if(plot=="ggplot"){return(g)}else{return(p)}
}

random<-function(time_serie, type, plot){
  n=length(time_serie)
  date=c()
  if(type=="MONTHLY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "month")
    periodo=12
  }
  if(type=="YEARLY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "year")
    periodo=1
  }
  if(type=="QUARTELY"){
    start<-paste(start(time_serie)[1],start(time_serie)[2],1,sep="/") %>% ymd()
    end<-paste(end(time_serie)[1],end(time_serie)[2],1,sep="/") %>% ymd()
    date<-seq.Date(from = start, to = end, by = "quarter")
    periodo=4
  }

  seas<-matrix(time_serie, nrow = length(time_serie)/periodo, byrow = T)
  means=c()
  for(i in 1:periodo){
    means<-c(means,mean(seas[,i]))[-13]
  }
  media=mean(means)
  means<-rep(means, periodo)
  seasonal<-means-media

  time=(1:length(time_serie))

  linear_reg<-lm(time_serie~time, time_serie)
  slope<-linear_reg$coefficients[2]
  inter<-linear_reg$coefficients[1]

  trend<-inter+ time*slope
  random<-time_serie-seasonal-trend
  df<-data.frame(random, date)
  g<-ggplot(df)+geom_line( aes(x=df$date, y=df$random))+theme_grey()+labs(x="date", y="time serie")+ggtitle(paste("serie"))+ theme(legend.position="none")+transition_reveal(date)
  p <- df %>%
    ggplot( aes(x=date, y=random)) +
    geom_area(fill="#69b3a2", alpha=0.5) +
    geom_line(color="#69b3a2") +
    ylab("random") +
    theme_ipsum()

  # Turn it interactive with ggplotly
  p <- ggplotly(p)

  if(plot=="ggplot"){return(g)}else{return(p)}
}


austres<-ts(austres[-89], start=c(1971,2))
#install.packages("tsview")
require(tsview)
#tsview::random(AirPassengers, "MONTHLY", "ggplot")
tsview::plot_serie(AirPassengers, "MONTHLY", "plot")
tsview::plot_serie(AirPassengers, "MONTHLY", "ggplot")

tsview::get_serie(AirPassengers, "MONTHLY")$random
##           date time_serie   seasonal     trend       random
## 1   1949-01-01        112 -38.548611  90.30996  60.23864943
## 2   1949-02-01        118 -45.298611  92.96715  70.33146552
## 3   1949-03-01        132 -10.131944  95.62433  46.50761494
## 4   1949-04-01        129 -13.215278  98.28151  43.93376437
## 5   1949-05-01        121  -8.465278 100.93870  28.52658046
## 6   1949-06-01        135  31.368056 103.59588   0.03606322
## 7   1949-07-01        148  71.034722 106.25307 -29.28778736
## 8   1949-08-01        148  70.784722 108.91025 -31.69497126
## 9   1949-09-01        136  22.118056 111.56743   2.31451149
## 10  1949-10-01        119 -13.715278 114.22462  18.49066092
## 11  1949-11-01        104 -47.465278 116.88180  34.58347701
## 12  1949-12-01        118 -18.465278 119.53898  16.92629310
## 13  1950-01-01        115 -38.548611 122.19617  31.35244253
## 14  1950-02-01        126 -45.298611 124.85335  46.44525862
## 15  1950-03-01        141 -10.131944 127.51054  23.62140805
## 16  1950-04-01        135 -13.215278 130.16772  18.04755747
## 17  1950-05-01        125  -8.465278 132.82490   0.64037356
## 18  1950-06-01        149  31.368056 135.48209 -17.85014368
## 19  1950-07-01        170  71.034722 138.13927 -39.17399425
## 20  1950-08-01        170  70.784722 140.79646 -41.58117816
## 21  1950-09-01        158  22.118056 143.45364  -7.57169540
## 22  1950-10-01        133 -13.715278 146.11082   0.60445402
## 23  1950-11-01        114 -47.465278 148.76801  12.69727011
## 24  1950-12-01        140 -18.465278 151.42519   7.04008621
## 25  1951-01-01        145 -38.548611 154.08238  29.46623563
## 26  1951-02-01        150 -45.298611 156.73956  38.55905172
## 27  1951-03-01        178 -10.131944 159.39674  28.73520115
## 28  1951-04-01        163 -13.215278 162.05393  14.16135057
## 29  1951-05-01        172  -8.465278 164.71111  15.75416667
## 30  1951-06-01        178  31.368056 167.36830 -20.73635057
## 31  1951-07-01        199  71.034722 170.02548 -42.06020115
## 32  1951-08-01        199  70.784722 172.68266 -44.46738506
## 33  1951-09-01        184  22.118056 175.33985 -13.45790230
## 34  1951-10-01        162 -13.715278 177.99703  -2.28175287
## 35  1951-11-01        146 -47.465278 180.65421  12.81106322
## 36  1951-12-01        166 -18.465278 183.31140   1.15387931
## 37  1952-01-01        171 -38.548611 185.96858  23.58002874
## 38  1952-02-01        180 -45.298611 188.62577  36.67284483
## 39  1952-03-01        193 -10.131944 191.28295  11.84899425
## 40  1952-04-01        181 -13.215278 193.94013   0.27514368
## 41  1952-05-01        183  -8.465278 196.59732  -5.13204023
## 42  1952-06-01        218  31.368056 199.25450 -12.62255747
## 43  1952-07-01        230  71.034722 201.91169 -42.94640805
## 44  1952-08-01        242  70.784722 204.56887 -33.35359195
## 45  1952-09-01        209  22.118056 207.22605 -20.34410920
## 46  1952-10-01        191 -13.715278 209.88324  -5.16795977
## 47  1952-11-01        172 -47.465278 212.54042   6.92485632
## 48  1952-12-01        194 -18.465278 215.19761  -2.73232759
## 49  1953-01-01        196 -38.548611 217.85479  16.69382184
## 50  1953-02-01        196 -45.298611 220.51197  20.78663793
## 51  1953-03-01        236 -10.131944 223.16916  22.96278736
## 52  1953-04-01        235 -13.215278 225.82634  22.38893678
## 53  1953-05-01        229  -8.465278 228.48352   8.98175287
## 54  1953-06-01        243  31.368056 231.14071 -19.50876437
## 55  1953-07-01        264  71.034722 233.79789 -40.83261494
## 56  1953-08-01        272  70.784722 236.45508 -35.23979885
## 57  1953-09-01        237  22.118056 239.11226 -24.23031609
## 58  1953-10-01        211 -13.715278 241.76944 -17.05416667
## 59  1953-11-01        180 -47.465278 244.42663 -16.96135057
## 60  1953-12-01        201 -18.465278 247.08381 -27.61853448
## 61  1954-01-01        204 -38.548611 249.74100  -7.19238506
## 62  1954-02-01        188 -45.298611 252.39818 -19.09956897
## 63  1954-03-01        235 -10.131944 255.05536  -9.92341954
## 64  1954-04-01        227 -13.215278 257.71255 -17.49727011
## 65  1954-05-01        234  -8.465278 260.36973 -17.90445402
## 66  1954-06-01        264  31.368056 263.02692 -30.39497126
## 67  1954-07-01        302  71.034722 265.68410 -34.71882184
## 68  1954-08-01        293  70.784722 268.34128 -46.12600575
## 69  1954-09-01        259  22.118056 270.99847 -34.11652299
## 70  1954-10-01        229 -13.715278 273.65565 -30.94037356
## 71  1954-11-01        203 -47.465278 276.31284 -25.84755747
## 72  1954-12-01        229 -18.465278 278.97002 -31.50474138
## 73  1955-01-01        242 -38.548611 281.62720  -1.07859195
## 74  1955-02-01        233 -45.298611 284.28439  -5.98577586
## 75  1955-03-01        267 -10.131944 286.94157  -9.80962644
## 76  1955-04-01        269 -13.215278 289.59875  -7.38347701
## 77  1955-05-01        270  -8.465278 292.25594 -13.79066092
## 78  1955-06-01        315  31.368056 294.91312 -11.28117816
## 79  1955-07-01        364  71.034722 297.57031  -4.60502874
## 80  1955-08-01        347  70.784722 300.22749 -24.01221264
## 81  1955-09-01        312  22.118056 302.88467 -13.00272989
## 82  1955-10-01        274 -13.715278 305.54186 -17.82658046
## 83  1955-11-01        237 -47.465278 308.19904 -23.73376437
## 84  1955-12-01        278 -18.465278 310.85623 -14.39094828
## 85  1956-01-01        284 -38.548611 313.51341   9.03520115
## 86  1956-02-01        277 -45.298611 316.17059   6.12801724
## 87  1956-03-01        317 -10.131944 318.82778   8.30416667
## 88  1956-04-01        313 -13.215278 321.48496   4.73031609
## 89  1956-05-01        318  -8.465278 324.14215   2.32313218
## 90  1956-06-01        374  31.368056 326.79933  15.83261494
## 91  1956-07-01        413  71.034722 329.45651  12.50876437
## 92  1956-08-01        405  70.784722 332.11370   2.10158046
## 93  1956-09-01        355  22.118056 334.77088  -1.88893678
## 94  1956-10-01        306 -13.715278 337.42807 -17.71278736
## 95  1956-11-01        271 -47.465278 340.08525 -21.61997126
## 96  1956-12-01        306 -18.465278 342.74243 -18.27715517
## 97  1957-01-01        315 -38.548611 345.39962   8.14899425
## 98  1957-02-01        301 -45.298611 348.05680  -1.75818966
## 99  1957-03-01        356 -10.131944 350.71398  15.41795977
## 100 1957-04-01        348 -13.215278 353.37117   7.84410920
## 101 1957-05-01        355  -8.465278 356.02835   7.43692529
## 102 1957-06-01        422  31.368056 358.68554  31.94640805
## 103 1957-07-01        465  71.034722 361.34272  32.62255747
## 104 1957-08-01        467  70.784722 363.99990  32.21537356
## 105 1957-09-01        404  22.118056 366.65709  15.22485632
## 106 1957-10-01        347 -13.715278 369.31427  -8.59899425
## 107 1957-11-01        305 -47.465278 371.97146 -19.50617816
## 108 1957-12-01        336 -18.465278 374.62864 -20.16336207
## 109 1958-01-01        340 -38.548611 377.28582   1.26278736
## 110 1958-02-01        318 -45.298611 379.94301 -16.64439655
## 111 1958-03-01        362 -10.131944 382.60019 -10.46824713
## 112 1958-04-01        348 -13.215278 385.25738 -24.04209770
## 113 1958-05-01        363  -8.465278 387.91456 -16.44928161
## 114 1958-06-01        435  31.368056 390.57174  13.06020115
## 115 1958-07-01        491  71.034722 393.22893  26.73635057
## 116 1958-08-01        505  70.784722 395.88611  38.32916667
## 117 1958-09-01        404  22.118056 398.54330 -16.66135057
## 118 1958-10-01        359 -13.715278 401.20048 -28.48520115
## 119 1958-11-01        310 -47.465278 403.85766 -46.39238506
## 120 1958-12-01        337 -18.465278 406.51485 -51.04956897
## 121 1959-01-01        360 -38.548611 409.17203 -10.62341954
## 122 1959-02-01        342 -45.298611 411.82921 -24.53060345
## 123 1959-03-01        406 -10.131944 414.48640   1.64554598
## 124 1959-04-01        396 -13.215278 417.14358  -7.92830460
## 125 1959-05-01        420  -8.465278 419.80077   8.66451149
## 126 1959-06-01        472  31.368056 422.45795  18.17399425
## 127 1959-07-01        548  71.034722 425.11513  51.85014368
## 128 1959-08-01        559  70.784722 427.77232  60.44295977
## 129 1959-09-01        463  22.118056 430.42950  10.45244253
## 130 1959-10-01        407 -13.715278 433.08669 -12.37140805
## 131 1959-11-01        362 -47.465278 435.74387 -26.27859195
## 132 1959-12-01        405 -18.465278 438.40105 -14.93577586
## 133 1960-01-01        417 -38.548611 441.05824  14.49037356
## 134 1960-02-01        391 -45.298611 443.71542  -7.41681034
## 135 1960-03-01        419 -10.131944 446.37261 -17.24066092
## 136 1960-04-01        461 -13.215278 449.02979  25.18548851
## 137 1960-05-01        472  -8.465278 451.68697  28.77830460
## 138 1960-06-01        535  31.368056 454.34416  49.28778736
## 139 1960-07-01        622  71.034722 457.00134  93.96393678
## 140 1960-08-01        606  70.784722 459.65852  75.55675287
## 141 1960-09-01        508  22.118056 462.31571  23.56623563
## 142 1960-10-01        461 -13.715278 464.97289   9.74238506
## 143 1960-11-01        390 -47.465278 467.63008 -30.16479885
## 144 1960-12-01        432 -18.465278 470.28726 -19.82198276
##               Jan          Feb          Mar          Apr          May
## 1949  60.23864943  70.33146552  46.50761494  43.93376437  28.52658046
## 1950  31.35244253  46.44525862  23.62140805  18.04755747   0.64037356
## 1951  29.46623563  38.55905172  28.73520115  14.16135057  15.75416667
## 1952  23.58002874  36.67284483  11.84899425   0.27514368  -5.13204023
## 1953  16.69382184  20.78663793  22.96278736  22.38893678   8.98175287
## 1954  -7.19238506 -19.09956897  -9.92341954 -17.49727011 -17.90445402
## 1955  -1.07859195  -5.98577586  -9.80962644  -7.38347701 -13.79066092
## 1956   9.03520115   6.12801724   8.30416667   4.73031609   2.32313218
## 1957   8.14899425  -1.75818966  15.41795977   7.84410920   7.43692529
## 1958   1.26278736 -16.64439655 -10.46824713 -24.04209770 -16.44928161
## 1959 -10.62341954 -24.53060345   1.64554598  -7.92830460   8.66451149
## 1960  14.49037356  -7.41681034 -17.24066092  25.18548851  28.77830460
##               Jun          Jul          Aug          Sep          Oct
## 1949   0.03606322 -29.28778736 -31.69497126   2.31451149  18.49066092
## 1950 -17.85014368 -39.17399425 -41.58117816  -7.57169540   0.60445402
## 1951 -20.73635057 -42.06020115 -44.46738506 -13.45790230  -2.28175287
## 1952 -12.62255747 -42.94640805 -33.35359195 -20.34410920  -5.16795977
## 1953 -19.50876437 -40.83261494 -35.23979885 -24.23031609 -17.05416667
## 1954 -30.39497126 -34.71882184 -46.12600575 -34.11652299 -30.94037356
## 1955 -11.28117816  -4.60502874 -24.01221264 -13.00272989 -17.82658046
## 1956  15.83261494  12.50876437   2.10158046  -1.88893678 -17.71278736
## 1957  31.94640805  32.62255747  32.21537356  15.22485632  -8.59899425
## 1958  13.06020115  26.73635057  38.32916667 -16.66135057 -28.48520115
## 1959  18.17399425  51.85014368  60.44295977  10.45244253 -12.37140805
## 1960  49.28778736  93.96393678  75.55675287  23.56623563   9.74238506
##               Nov          Dec
## 1949  34.58347701  16.92629310
## 1950  12.69727011   7.04008621
## 1951  12.81106322   1.15387931
## 1952   6.92485632  -2.73232759
## 1953 -16.96135057 -27.61853448
## 1954 -25.84755747 -31.50474138
## 1955 -23.73376437 -14.39094828
## 1956 -21.61997126 -18.27715517
## 1957 -19.50617816 -20.16336207
## 1958 -46.39238506 -51.04956897
## 1959 -26.27859195 -14.93577586
## 1960 -30.16479885 -19.82198276
tsview::get_serie(AirPassengers, "MONTHLY")
##           date time_serie   seasonal     trend       random
## 1   1949-01-01        112 -38.548611  90.30996  60.23864943
## 2   1949-02-01        118 -45.298611  92.96715  70.33146552
## 3   1949-03-01        132 -10.131944  95.62433  46.50761494
## 4   1949-04-01        129 -13.215278  98.28151  43.93376437
## 5   1949-05-01        121  -8.465278 100.93870  28.52658046
## 6   1949-06-01        135  31.368056 103.59588   0.03606322
## 7   1949-07-01        148  71.034722 106.25307 -29.28778736
## 8   1949-08-01        148  70.784722 108.91025 -31.69497126
## 9   1949-09-01        136  22.118056 111.56743   2.31451149
## 10  1949-10-01        119 -13.715278 114.22462  18.49066092
## 11  1949-11-01        104 -47.465278 116.88180  34.58347701
## 12  1949-12-01        118 -18.465278 119.53898  16.92629310
## 13  1950-01-01        115 -38.548611 122.19617  31.35244253
## 14  1950-02-01        126 -45.298611 124.85335  46.44525862
## 15  1950-03-01        141 -10.131944 127.51054  23.62140805
## 16  1950-04-01        135 -13.215278 130.16772  18.04755747
## 17  1950-05-01        125  -8.465278 132.82490   0.64037356
## 18  1950-06-01        149  31.368056 135.48209 -17.85014368
## 19  1950-07-01        170  71.034722 138.13927 -39.17399425
## 20  1950-08-01        170  70.784722 140.79646 -41.58117816
## 21  1950-09-01        158  22.118056 143.45364  -7.57169540
## 22  1950-10-01        133 -13.715278 146.11082   0.60445402
## 23  1950-11-01        114 -47.465278 148.76801  12.69727011
## 24  1950-12-01        140 -18.465278 151.42519   7.04008621
## 25  1951-01-01        145 -38.548611 154.08238  29.46623563
## 26  1951-02-01        150 -45.298611 156.73956  38.55905172
## 27  1951-03-01        178 -10.131944 159.39674  28.73520115
## 28  1951-04-01        163 -13.215278 162.05393  14.16135057
## 29  1951-05-01        172  -8.465278 164.71111  15.75416667
## 30  1951-06-01        178  31.368056 167.36830 -20.73635057
## 31  1951-07-01        199  71.034722 170.02548 -42.06020115
## 32  1951-08-01        199  70.784722 172.68266 -44.46738506
## 33  1951-09-01        184  22.118056 175.33985 -13.45790230
## 34  1951-10-01        162 -13.715278 177.99703  -2.28175287
## 35  1951-11-01        146 -47.465278 180.65421  12.81106322
## 36  1951-12-01        166 -18.465278 183.31140   1.15387931
## 37  1952-01-01        171 -38.548611 185.96858  23.58002874
## 38  1952-02-01        180 -45.298611 188.62577  36.67284483
## 39  1952-03-01        193 -10.131944 191.28295  11.84899425
## 40  1952-04-01        181 -13.215278 193.94013   0.27514368
## 41  1952-05-01        183  -8.465278 196.59732  -5.13204023
## 42  1952-06-01        218  31.368056 199.25450 -12.62255747
## 43  1952-07-01        230  71.034722 201.91169 -42.94640805
## 44  1952-08-01        242  70.784722 204.56887 -33.35359195
## 45  1952-09-01        209  22.118056 207.22605 -20.34410920
## 46  1952-10-01        191 -13.715278 209.88324  -5.16795977
## 47  1952-11-01        172 -47.465278 212.54042   6.92485632
## 48  1952-12-01        194 -18.465278 215.19761  -2.73232759
## 49  1953-01-01        196 -38.548611 217.85479  16.69382184
## 50  1953-02-01        196 -45.298611 220.51197  20.78663793
## 51  1953-03-01        236 -10.131944 223.16916  22.96278736
## 52  1953-04-01        235 -13.215278 225.82634  22.38893678
## 53  1953-05-01        229  -8.465278 228.48352   8.98175287
## 54  1953-06-01        243  31.368056 231.14071 -19.50876437
## 55  1953-07-01        264  71.034722 233.79789 -40.83261494
## 56  1953-08-01        272  70.784722 236.45508 -35.23979885
## 57  1953-09-01        237  22.118056 239.11226 -24.23031609
## 58  1953-10-01        211 -13.715278 241.76944 -17.05416667
## 59  1953-11-01        180 -47.465278 244.42663 -16.96135057
## 60  1953-12-01        201 -18.465278 247.08381 -27.61853448
## 61  1954-01-01        204 -38.548611 249.74100  -7.19238506
## 62  1954-02-01        188 -45.298611 252.39818 -19.09956897
## 63  1954-03-01        235 -10.131944 255.05536  -9.92341954
## 64  1954-04-01        227 -13.215278 257.71255 -17.49727011
## 65  1954-05-01        234  -8.465278 260.36973 -17.90445402
## 66  1954-06-01        264  31.368056 263.02692 -30.39497126
## 67  1954-07-01        302  71.034722 265.68410 -34.71882184
## 68  1954-08-01        293  70.784722 268.34128 -46.12600575
## 69  1954-09-01        259  22.118056 270.99847 -34.11652299
## 70  1954-10-01        229 -13.715278 273.65565 -30.94037356
## 71  1954-11-01        203 -47.465278 276.31284 -25.84755747
## 72  1954-12-01        229 -18.465278 278.97002 -31.50474138
## 73  1955-01-01        242 -38.548611 281.62720  -1.07859195
## 74  1955-02-01        233 -45.298611 284.28439  -5.98577586
## 75  1955-03-01        267 -10.131944 286.94157  -9.80962644
## 76  1955-04-01        269 -13.215278 289.59875  -7.38347701
## 77  1955-05-01        270  -8.465278 292.25594 -13.79066092
## 78  1955-06-01        315  31.368056 294.91312 -11.28117816
## 79  1955-07-01        364  71.034722 297.57031  -4.60502874
## 80  1955-08-01        347  70.784722 300.22749 -24.01221264
## 81  1955-09-01        312  22.118056 302.88467 -13.00272989
## 82  1955-10-01        274 -13.715278 305.54186 -17.82658046
## 83  1955-11-01        237 -47.465278 308.19904 -23.73376437
## 84  1955-12-01        278 -18.465278 310.85623 -14.39094828
## 85  1956-01-01        284 -38.548611 313.51341   9.03520115
## 86  1956-02-01        277 -45.298611 316.17059   6.12801724
## 87  1956-03-01        317 -10.131944 318.82778   8.30416667
## 88  1956-04-01        313 -13.215278 321.48496   4.73031609
## 89  1956-05-01        318  -8.465278 324.14215   2.32313218
## 90  1956-06-01        374  31.368056 326.79933  15.83261494
## 91  1956-07-01        413  71.034722 329.45651  12.50876437
## 92  1956-08-01        405  70.784722 332.11370   2.10158046
## 93  1956-09-01        355  22.118056 334.77088  -1.88893678
## 94  1956-10-01        306 -13.715278 337.42807 -17.71278736
## 95  1956-11-01        271 -47.465278 340.08525 -21.61997126
## 96  1956-12-01        306 -18.465278 342.74243 -18.27715517
## 97  1957-01-01        315 -38.548611 345.39962   8.14899425
## 98  1957-02-01        301 -45.298611 348.05680  -1.75818966
## 99  1957-03-01        356 -10.131944 350.71398  15.41795977
## 100 1957-04-01        348 -13.215278 353.37117   7.84410920
## 101 1957-05-01        355  -8.465278 356.02835   7.43692529
## 102 1957-06-01        422  31.368056 358.68554  31.94640805
## 103 1957-07-01        465  71.034722 361.34272  32.62255747
## 104 1957-08-01        467  70.784722 363.99990  32.21537356
## 105 1957-09-01        404  22.118056 366.65709  15.22485632
## 106 1957-10-01        347 -13.715278 369.31427  -8.59899425
## 107 1957-11-01        305 -47.465278 371.97146 -19.50617816
## 108 1957-12-01        336 -18.465278 374.62864 -20.16336207
## 109 1958-01-01        340 -38.548611 377.28582   1.26278736
## 110 1958-02-01        318 -45.298611 379.94301 -16.64439655
## 111 1958-03-01        362 -10.131944 382.60019 -10.46824713
## 112 1958-04-01        348 -13.215278 385.25738 -24.04209770
## 113 1958-05-01        363  -8.465278 387.91456 -16.44928161
## 114 1958-06-01        435  31.368056 390.57174  13.06020115
## 115 1958-07-01        491  71.034722 393.22893  26.73635057
## 116 1958-08-01        505  70.784722 395.88611  38.32916667
## 117 1958-09-01        404  22.118056 398.54330 -16.66135057
## 118 1958-10-01        359 -13.715278 401.20048 -28.48520115
## 119 1958-11-01        310 -47.465278 403.85766 -46.39238506
## 120 1958-12-01        337 -18.465278 406.51485 -51.04956897
## 121 1959-01-01        360 -38.548611 409.17203 -10.62341954
## 122 1959-02-01        342 -45.298611 411.82921 -24.53060345
## 123 1959-03-01        406 -10.131944 414.48640   1.64554598
## 124 1959-04-01        396 -13.215278 417.14358  -7.92830460
## 125 1959-05-01        420  -8.465278 419.80077   8.66451149
## 126 1959-06-01        472  31.368056 422.45795  18.17399425
## 127 1959-07-01        548  71.034722 425.11513  51.85014368
## 128 1959-08-01        559  70.784722 427.77232  60.44295977
## 129 1959-09-01        463  22.118056 430.42950  10.45244253
## 130 1959-10-01        407 -13.715278 433.08669 -12.37140805
## 131 1959-11-01        362 -47.465278 435.74387 -26.27859195
## 132 1959-12-01        405 -18.465278 438.40105 -14.93577586
## 133 1960-01-01        417 -38.548611 441.05824  14.49037356
## 134 1960-02-01        391 -45.298611 443.71542  -7.41681034
## 135 1960-03-01        419 -10.131944 446.37261 -17.24066092
## 136 1960-04-01        461 -13.215278 449.02979  25.18548851
## 137 1960-05-01        472  -8.465278 451.68697  28.77830460
## 138 1960-06-01        535  31.368056 454.34416  49.28778736
## 139 1960-07-01        622  71.034722 457.00134  93.96393678
## 140 1960-08-01        606  70.784722 459.65852  75.55675287
## 141 1960-09-01        508  22.118056 462.31571  23.56623563
## 142 1960-10-01        461 -13.715278 464.97289   9.74238506
## 143 1960-11-01        390 -47.465278 467.63008 -30.16479885
## 144 1960-12-01        432 -18.465278 470.28726 -19.82198276
tsview::season_time_serie(AirPassengers, 12, "MONTHLY", "plot")
tsview::season_time_serie(AirPassengers, 12, "MONTHLY", "ggplot")

tsview::trend_sta(AirPassengers)

tsview::trend_sta(austres)