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

timeseries <- ts(myDataFrame)

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 which can be useful in pre-processing large time series data. You will need to create a account and remember your username and API key. Once that is done, add that into your .RProfile with the following 2 lines of code


Once this is complete you can create a normal figure using ggplot and then send it to plotly.

plot <- ggplot(df %>% 
                 filter(time > 480 & time < 500)) +
  aes(x = time, y = ecg) +
  geom_line(size = 1L, colour = "#0c4c8a") +
plotly::api_create(plot, filename = "Showoff_to_Joel")

plotly has a max file size you can send with a free account, but we can work around that by creating a local file

htmlwidgets::saveWidget(as_widget(plot), "index.html")

14.3 Installing Zotero

If you do plan on being able to write documents then I suggest using Zotero.