Seasonal Plot Plotting Techniques
1. Seasonal Subseries Plot
The seasonal subseries plot is a specialized plot for visualizing seasonal patterns in time series data. It consists of small multiples, with each panel representing a specific season or month. This plot allows for the comparison of seasonal patterns across different time periods, aiding in the identification of recurring patterns and anomalies.
2. Seasonal Decomposition Plot
The seasonal decomposition plot is used to decompose a time series into its constituent components: trend, seasonal, and residual. This plot helps visualize the underlying trend and seasonal variations present in the data, enabling analysts to better understand the structure and behavior of seasonal patterns over time.
3. Seasonal Heatmap
A seasonal heatmap is a graphical representation of seasonal patterns using color gradients. Each row in the heatmap represents a year, and each column represents a specific time period (e.g., month or week). The intensity of color indicates the magnitude of a particular variable (e.g., temperature) for each time period, allowing for easy identification of seasonal trends and variations.
4. Seasonal Line Plot
A seasonal line plot is similar to a regular time series plot but emphasizes seasonal patterns by aggregating data at regular intervals (e.g., monthly or quarterly). By plotting the mean or median values for each time period over multiple years, seasonal fluctuations become more apparent, facilitating the visualization of seasonal trends and changes over time.
5. Seasonal Boxplot
A seasonal boxplot displays the distribution of a variable across different seasons or months. Each boxplot represents the distribution of the variable for a specific season, allowing for comparison of central tendency, spread, and variability between different seasons. This plot is particularly useful for identifying seasonal outliers and understanding the variability of the data across seasons.
Dataset Link: WeatherHistory
Step 1: Load the required libraries and dataset
- Load the ggplot2 and lubridate library .
- Dataset is read from the CSV file located at the specified file path and stored in the variable weather_data.
# Load the required libraries
library(ggplot2)
library(lubridate)
# Load the dataset
weather_data <- read.csv("C:/Users/Tonmoy/Downloads/Dataset/weatherHistory.csv")
Step 2: Prepare the data
- Convert the ‘Formatted Date’ column to POSIXct format (datetime) using the as.POSIXct().
- Extract the year from the ‘Formatted Date’ column and store it in a new column named ‘Year’.
- Extract the month from the ‘Formatted Date’ column and store it in a new column named ‘Month’.
weather_data$Formatted.Date <- as.POSIXct(weather_data$Formatted.Date,
format="%Y-%m-%d %H:%M:%S", tz="UTC")
weather_data$Year <- year(weather_data$Formatted.Date)
weather_data$Month <- month(weather_data$Formatted.Date)
Step 3: Create a seasonal plot
- Use the ggplot() function to create a plot using the weather_data data frame as the data source.
- Add a line representing temperature for each month and year combination.
- Add a smooth curve to the plot using locally weighted scatterplot smoothing (LOESS) method.
- Add labels for x-axis, y-axis, and title of the plot.
- Apply a minimal theme to the plot.
- It prints the created seasonal plot to the R console, allowing the user to visually inspect the temperature variations over months.
# Create a seasonal plot
seasonal_plot <- ggplot(weather_data, aes(x = Month,
y = Temperature..C., group = Year)) +
geom_line(aes(color = factor(Year))) +
geom_smooth(method = "loess", se = FALSE) +
labs(x = "Month", y = "Temperature (C)", title = "Seasonal Temperature Plot") +
theme_minimal()
# Display the plot
print(seasonal_plot)
Output:
Seasonal Plot of Humidity
We can plot humidity over months to visualize how humidity varies throughout the year.
# Create a seasonal plot of humidity
seasonal_humidity_plot <- ggplot(weather_data,
aes(x = Month, y = Humidity, group = Year)) +
geom_line(aes(color = factor(Year))) +
geom_smooth(method = "loess", se = FALSE) +
labs(x = "Month", y = "Humidity", title = "Seasonal Humidity Plot") +
theme_minimal()
# Display the plot
print(seasonal_humidity_plot)
Output:
Seasonal Plot of Wind Speed
Plot wind speed over months to observe seasonal variations in wind patterns.
# Create a seasonal plot of wind speed
seasonal_wind_plot <- ggplot(weather_data, aes(x = Month,
y = Wind.Speed..km.h., group = Year)) +
geom_line(aes(color = factor(Year))) +
geom_smooth(method = "loess", se = FALSE) +
labs(x = "Month", y = "Wind Speed (km/h)", title = "Seasonal Wind Speed Plot") +
theme_minimal()
# Display the plot
print(seasonal_wind_plot)
Output:
Seasonal Plot of Visibility
Plot visibility over months to see how visibility changes with seasons.
# Create a seasonal plot of visibility
seasonal_visibility_plot <- ggplot(weather_data,
aes(x = Month, y = Visibility..km., group = Year)) +
geom_line(aes(color = factor(Year))) +
geom_smooth(method = "loess", se = FALSE) +
labs(x = "Month", y = "Visibility (km)", title = "Seasonal Visibility Plot") +
theme_minimal()
# Display the plot
print(seasonal_visibility_plot)
Output:
Seasonal Plots in R
A seasonal plot is a graphical representation used to visualize and analyze seasonal patterns in time series data. It helps identify recurring patterns, such as monthly or quarterly fluctuations, within a dataset.
For example, let’s consider a retail store that sells winter clothing. The store collects sales data for sweaters over the past few years. By creating a seasonal plot of sweater sales data, the store can observe if there is a consistent increase in sales during the colder months (fall and winter) compared to the warmer months (spring and summer). This visualization can help the store better understand the seasonal demand for sweaters and plan their inventory accordingly.