generated from onwidget/astrowind
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c462f23
commit 51a4559
Showing
39 changed files
with
1,845 additions
and
15 deletions.
There are no files selected for viewing
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.
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.
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.
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.
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
122
src/content/blog/cs/visualizing-time-series-data-in-r.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
src/content/blog/da/visualizing-time-series-data-in-r.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
src/content/blog/de/visualizing-time-series-data-in-r.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.