%%{init: {'themeVariables': { 'fontSize': '15pt'}}
flowchart TD
A[Raw Time Series Data] --> B{Data Structure}
B -->|Traditional| C[Specialized TS Objects]
B -->|Tidy| D[tsibble]
C --> E[Limited Functions]
C --> F[Complex Syntax]
C --> G[Isolated Workflow]
D --> H[dplyr Verbs]
D --> I[ggplot2 Graphics]
D --> J[Tidyverse Integration]
H --> K[filter, mutate, summarize...]
I --> L[geom_line, facet_wrap...]
J --> M[Seamless Data Pipeline]
K --> N[Flexible Analysis]
L --> N
M --> N
E --> O[Rigid Analysis]
F --> O
G --> O
style D fill:#e1f5fe
style N fill:#c8e6c9
style O fill:#ffcdd2
Working with Time Series Data
Time is the most fundamental dimension in data analysis, yet working with temporal data has traditionally been one of the most frustrating aspects of data science. If you have ever felt less enthusiastic trying to force dates and data into a standard data frame, then here is some good news for you. The Tidyverse provides a coherent, intuitive framework for taming the chaos of temporal data.
In this section, we will explore how to work with time series data using the tidy data principles. Rather than wrestling with complex time series objects or memorising some mysterious date formatting codes, you will learn to treat temporal data as just another type of structured data that can be manipulated, visualised and modelled using the same consistent grammar you already know.
The tidy Approach to Time Series
Traditional time series analysis in R has been handled using ts objects and packages like forecast. These are still useful, but they do not fit perfectly with the modern tidyverse philosophy. The tidy approach treats time series as regular dataframes which extends the tibble data structure by incorporating time series components (index and key).
# A tsibble: 6 x 5 [1Q]
# Key: Region, State, Purpose [1]
Quarter Region State Purpose Trips
<qtr> <chr> <chr> <chr> <dbl>
1 1998 Q1 Adelaide South Australia Business 135.
2 1998 Q2 Adelaide South Australia Business 110.
3 1998 Q3 Adelaide South Australia Business 166.
4 1998 Q4 Adelaide South Australia Business 127.
5 1999 Q1 Adelaide South Australia Business 137.
6 1999 Q2 Adelaide South Australia Business 200.
This approach unlocks the full power of dplyr's data manipulation verbs, ggplot2's visualisation capabilities and the broader tidyverse ecosystem for temporal data analysis.
What We will Cover
This section is organised into three complementary chapters that builds your time series skills progressively.
4 Tidy Time Series Basics: This chapter will help you master the fundamental building blocks of time series data analysis. It establishes the foundation for all subsequent time series work.
5 Dealing with Time Gaps and Irregularities: Real world time series data is messy, with missing observations, irregular intervals and unexpected gaps. This chapter teaches you to identify understand and handle these imperfections.
6 Importing Data and Creating a tsibble (Bonus): Time series data comes from everywhere – csv files, APIs, databases and excel files. Some of these sources might have inconsistent date formats, dates being stored as strings and time zones being mixed up. In this chapter you will be provided with practical strategies for importing temporal data and handling different date formats.
Throughout this section we will primarily use these essential packages lubridate, tsibble, dplyr, tidyr. By the end of this section you will have mastered the crucial first step in any time series analysis: creating a valid, gap-aware tsibble from raw data. This is not just busy work, it is about building a solid foundation.
A well structured tsibble ensures that every analysis, visualisation, and forecast that follows is built on accurate and understandable temporal data.