Chapter 14 Time Series
Working with Time Series Data
The first think you will need to do is convert you data.frame into a time series
<- ts(myDataFrame) timeseries
Although I recommended using ggplot earlier in this book, when it comes to time series data, dynamic plots can be useful
14.1 plotly
This is not recommended for most users but you can also create dynamic plots with plot.ly which can be useful in pre-processing large time series data. You will need to create a plot.ly account and remember your username and API key. Once that is done, add that into your .RProfile with the following 2 lines of code
Sys.setenv("plotly_username"="your_plotly_username")
Sys.setenv("plotly_api_key"="your_api_key")
Once this is complete you can create a normal figure using ggplot and then send it to plotly.
<- ggplot(df %>%
plot filter(time > 480 & time < 500)) +
aes(x = time, y = ecg) +
geom_line(size = 1L, colour = "#0c4c8a") +
theme_minimal()
::api_create(plot, filename = "Showoff_to_Joel") plotly
plotly has a max file size you can send with a free account, but we can work around that by creating a local file
::saveWidget(as_widget(plot), "index.html") htmlwidgets
14.2 Useful Links
https://a-little-book-of-r-for-time-series.readthedocs.io/en/latest/src/timeseries.html https://rstudio-pubs-static.s3.amazonaws.com/84226_ad792383c050483bbae4676bc76a4038.html
RcppRoll package seems very useful.
[tsvis](github.com/nevrome/wellspell.addin)
seems like a great package to visualize time-series data