Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
garethbilaney committed Sep 26, 2023
1 parent c462f23 commit 51a4559
Show file tree
Hide file tree
Showing 39 changed files with 1,845 additions and 15 deletions.
Binary file added src/assets/images/acf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/forecast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/histogram-of-residuals.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/mock-comp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/pacf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/residuals-asc-of-residuals.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/time-ser-via-ggplot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions src/content/blog/cs/visualizing-time-series-data-in-r.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: "Visualizing Time Series Data in R: A Beginner's Guide"
description: "An introductory guide to visualizing time series data in R. Discover foundational techniques, from basic plots to custom visuals using ggplot2, and gain insights into your data."
tags: ["R", "dataviz", "Data Visualization", "Time Series"]
authors: ["Datanautes"]
date: "2023-09-21"
isLocalized: false
---

Time series analysis helps us understand trends and predict future values in areas like finance, weather, and sales. Using R, a key tool for statistics, we can visualize this data for better understanding. This post will introduce basic visualization techniques for time series data in R.

Before anything, make sure to install and load `forecast`:
```r
install.packages('forecast', dependencies = TRUE)
library(forecast)

```

### **1. Starting with the Basics: The Initial Plot**

The first step in any time series analysis is to simply visualize the raw data. In R, the `plot()` function serves this purpose:

```r
plot(AirPassengers, xlab="Time", ylab="Number of Passengers",
main="Monthly Airline Passengers Data")

```

![Monthly Airline Passengers Data](@assets/images/monthly-airline-passengers-data.png)

This basic visualization gives us an understanding of the general trends and patterns.

### **2. Unraveling the Mystery: Decomposition**

Once we have our basic plot, we can break our time series down into its core components: trend, seasonality, and residuals.

```r
decomposition <- decompose(AirPassengers)
plot(decomposition)
```

![decomposition of additive time series](@assets/images/decomposition-of-additive-time-series.png)

This decomposition allows us to see the underlying trend, any seasonality component, and the residuals (or noise) separately.

### **3. Digging Deeper: Understanding Correlation with ACF and PACF**

The Auto-correlation function (ACF) and the partial auto-correlation function (PACF) are tools to measure and visualize the correlation in time series data:

```r
acf(AirPassengers)
pacf(AirPassengers)
```

![acf](@assets/images/acf.png)

![pacf](@assets/images/pacf.png)


### **4. Diagnosing our Models**

After fitting a model, such as ARIMA, it's important to visualize the residuals to understand the model's fit:

```r
fit <- auto.arima(AirPassengers)
# Setting up the plotting window to 2x1 for the first two plots
par(mfrow=c(1,2))

# Plot residuals
plot(fit$residuals, main="Residuals over Time")

# ACF of residuals
acf(fit$residuals, main="ACF of Residuals")

# Reset graphical parameters to default
par(mfrow=c(1,1))
```
![Residuals vs. ACF of residuals](@assets/images/residuals-asc-of-residuals.png)

```r
# Histogram of residuals
hist(fit$residuals, main="Histogram of Residuals")
```

![Histogram of residuals](@assets/images/histogram-of-residuals.png)

### **5. Gazing into the Future: Forecast Visualizations**

To understand the potential future values and their prediction intervals, we can visualize forecasts:

```r
future <- forecast(fit, h=24)
plot(future)
```

![Forecast](@assets/images/forecast.png)

### **6. Comparing and Contrasting: Multiple Time Series Visualization**

For datasets where multiple time series need to be compared. Here is a (more) generic example:

```r
ts.plot(ts1, ts2, ts3, col=c("blue", "red", "green"))
```

![Comparing and Contrasting: Multiple Time Series Visualization](@assets/images/mock-comp.png)

### **7. Aesthetic and Custom Visuals with `ggplot2`**

For those who crave more customized visuals, the `ggplot2` package in R is a treasure:

```r
library(ggplot2)
autoplot(AirPassengers) +
labs(title = "Monthly Airline Passengers Data",
x = "Time", y = "Number of Passengers") +
theme_minimal()
```
![Custom Visuals with ggplot2](@assets/images/time-ser-via-ggplot2.png)


In conclusion, visualizing time series data in R can range from basic plots to more advanced, custom visuals. The tools and functions in R make it a versatile choice for time series analysis. As you dive deeper into this realm, always remember: the essence of visualization is clarity. Choose elements that make your data shine and tell its story effectively.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This is a non-numbered subsection.
```
### Result:

![](/images/working-with-non-numbered-sections-in-latex.png)
![](@assets/images/working-with-non-numbered-sections-in-latex.png)

## Wrapping Up

Expand Down
122 changes: 122 additions & 0 deletions src/content/blog/da/visualizing-time-series-data-in-r.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: "Visualizing Time Series Data in R: A Beginner's Guide"
description: "An introductory guide to visualizing time series data in R. Discover foundational techniques, from basic plots to custom visuals using ggplot2, and gain insights into your data."
tags: ["R", "dataviz", "Data Visualization", "Time Series"]
authors: ["Datanautes"]
date: "2023-09-21"
isLocalized: false
---

Time series analysis helps us understand trends and predict future values in areas like finance, weather, and sales. Using R, a key tool for statistics, we can visualize this data for better understanding. This post will introduce basic visualization techniques for time series data in R.

Before anything, make sure to install and load `forecast`:
```r
install.packages('forecast', dependencies = TRUE)
library(forecast)

```

### **1. Starting with the Basics: The Initial Plot**

The first step in any time series analysis is to simply visualize the raw data. In R, the `plot()` function serves this purpose:

```r
plot(AirPassengers, xlab="Time", ylab="Number of Passengers",
main="Monthly Airline Passengers Data")

```

![Monthly Airline Passengers Data](@assets/images/monthly-airline-passengers-data.png)

This basic visualization gives us an understanding of the general trends and patterns.

### **2. Unraveling the Mystery: Decomposition**

Once we have our basic plot, we can break our time series down into its core components: trend, seasonality, and residuals.

```r
decomposition <- decompose(AirPassengers)
plot(decomposition)
```

![decomposition of additive time series](@assets/images/decomposition-of-additive-time-series.png)

This decomposition allows us to see the underlying trend, any seasonality component, and the residuals (or noise) separately.

### **3. Digging Deeper: Understanding Correlation with ACF and PACF**

The Auto-correlation function (ACF) and the partial auto-correlation function (PACF) are tools to measure and visualize the correlation in time series data:

```r
acf(AirPassengers)
pacf(AirPassengers)
```

![acf](@assets/images/acf.png)

![pacf](@assets/images/pacf.png)


### **4. Diagnosing our Models**

After fitting a model, such as ARIMA, it's important to visualize the residuals to understand the model's fit:

```r
fit <- auto.arima(AirPassengers)
# Setting up the plotting window to 2x1 for the first two plots
par(mfrow=c(1,2))

# Plot residuals
plot(fit$residuals, main="Residuals over Time")

# ACF of residuals
acf(fit$residuals, main="ACF of Residuals")

# Reset graphical parameters to default
par(mfrow=c(1,1))
```
![Residuals vs. ACF of residuals](@assets/images/residuals-asc-of-residuals.png)

```r
# Histogram of residuals
hist(fit$residuals, main="Histogram of Residuals")
```

![Histogram of residuals](@assets/images/histogram-of-residuals.png)

### **5. Gazing into the Future: Forecast Visualizations**

To understand the potential future values and their prediction intervals, we can visualize forecasts:

```r
future <- forecast(fit, h=24)
plot(future)
```

![Forecast](@assets/images/forecast.png)

### **6. Comparing and Contrasting: Multiple Time Series Visualization**

For datasets where multiple time series need to be compared. Here is a (more) generic example:

```r
ts.plot(ts1, ts2, ts3, col=c("blue", "red", "green"))
```

![Comparing and Contrasting: Multiple Time Series Visualization](@assets/images/mock-comp.png)

### **7. Aesthetic and Custom Visuals with `ggplot2`**

For those who crave more customized visuals, the `ggplot2` package in R is a treasure:

```r
library(ggplot2)
autoplot(AirPassengers) +
labs(title = "Monthly Airline Passengers Data",
x = "Time", y = "Number of Passengers") +
theme_minimal()
```
![Custom Visuals with ggplot2](@assets/images/time-ser-via-ggplot2.png)


In conclusion, visualizing time series data in R can range from basic plots to more advanced, custom visuals. The tools and functions in R make it a versatile choice for time series analysis. As you dive deeper into this realm, always remember: the essence of visualization is clarity. Choose elements that make your data shine and tell its story effectively.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This is a non-numbered subsection.
```
### Result:

![](/images/working-with-non-numbered-sections-in-latex.png)
![](@assets/images/working-with-non-numbered-sections-in-latex.png)

## Wrapping Up

Expand Down
122 changes: 122 additions & 0 deletions src/content/blog/de/visualizing-time-series-data-in-r.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: "Visualizing Time Series Data in R: A Beginner's Guide"
description: "An introductory guide to visualizing time series data in R. Discover foundational techniques, from basic plots to custom visuals using ggplot2, and gain insights into your data."
tags: ["R", "dataviz", "Data Visualization", "Time Series"]
authors: ["Datanautes"]
date: "2023-09-21"
isLocalized: false
---

Time series analysis helps us understand trends and predict future values in areas like finance, weather, and sales. Using R, a key tool for statistics, we can visualize this data for better understanding. This post will introduce basic visualization techniques for time series data in R.

Before anything, make sure to install and load `forecast`:
```r
install.packages('forecast', dependencies = TRUE)
library(forecast)

```

### **1. Starting with the Basics: The Initial Plot**

The first step in any time series analysis is to simply visualize the raw data. In R, the `plot()` function serves this purpose:

```r
plot(AirPassengers, xlab="Time", ylab="Number of Passengers",
main="Monthly Airline Passengers Data")

```

![Monthly Airline Passengers Data](@assets/images/monthly-airline-passengers-data.png)

This basic visualization gives us an understanding of the general trends and patterns.

### **2. Unraveling the Mystery: Decomposition**

Once we have our basic plot, we can break our time series down into its core components: trend, seasonality, and residuals.

```r
decomposition <- decompose(AirPassengers)
plot(decomposition)
```

![decomposition of additive time series](@assets/images/decomposition-of-additive-time-series.png)

This decomposition allows us to see the underlying trend, any seasonality component, and the residuals (or noise) separately.

### **3. Digging Deeper: Understanding Correlation with ACF and PACF**

The Auto-correlation function (ACF) and the partial auto-correlation function (PACF) are tools to measure and visualize the correlation in time series data:

```r
acf(AirPassengers)
pacf(AirPassengers)
```

![acf](@assets/images/acf.png)

![pacf](@assets/images/pacf.png)


### **4. Diagnosing our Models**

After fitting a model, such as ARIMA, it's important to visualize the residuals to understand the model's fit:

```r
fit <- auto.arima(AirPassengers)
# Setting up the plotting window to 2x1 for the first two plots
par(mfrow=c(1,2))

# Plot residuals
plot(fit$residuals, main="Residuals over Time")

# ACF of residuals
acf(fit$residuals, main="ACF of Residuals")

# Reset graphical parameters to default
par(mfrow=c(1,1))
```
![Residuals vs. ACF of residuals](@assets/images/residuals-asc-of-residuals.png)

```r
# Histogram of residuals
hist(fit$residuals, main="Histogram of Residuals")
```

![Histogram of residuals](@assets/images/histogram-of-residuals.png)

### **5. Gazing into the Future: Forecast Visualizations**

To understand the potential future values and their prediction intervals, we can visualize forecasts:

```r
future <- forecast(fit, h=24)
plot(future)
```

![Forecast](@assets/images/forecast.png)

### **6. Comparing and Contrasting: Multiple Time Series Visualization**

For datasets where multiple time series need to be compared. Here is a (more) generic example:

```r
ts.plot(ts1, ts2, ts3, col=c("blue", "red", "green"))
```

![Comparing and Contrasting: Multiple Time Series Visualization](@assets/images/mock-comp.png)

### **7. Aesthetic and Custom Visuals with `ggplot2`**

For those who crave more customized visuals, the `ggplot2` package in R is a treasure:

```r
library(ggplot2)
autoplot(AirPassengers) +
labs(title = "Monthly Airline Passengers Data",
x = "Time", y = "Number of Passengers") +
theme_minimal()
```
![Custom Visuals with ggplot2](@assets/images/time-ser-via-ggplot2.png)


In conclusion, visualizing time series data in R can range from basic plots to more advanced, custom visuals. The tools and functions in R make it a versatile choice for time series analysis. As you dive deeper into this realm, always remember: the essence of visualization is clarity. Choose elements that make your data shine and tell its story effectively.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This is a non-numbered subsection.
```
### Result:

![](/images/working-with-non-numbered-sections-in-latex.png)
![](@assets/images/working-with-non-numbered-sections-in-latex.png)

## Wrapping Up

Expand Down
Loading

0 comments on commit 51a4559

Please sign in to comment.