# Load necessary libraries
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("dplyr")) install.packages("dplyr")
library(ggplot2)
library(dplyr)
# 1. Create the Dataset
# Note: For split years (Pantone 2016/2021), we average the RGB values
colors_ts <- data.frame(
year = c(
# Pantone
2026, 2025, 2024, 2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016,
# Benjamin Moore
2026, 2025, 2024, 2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016,
# Sherwin-Williams
2026, 2025, 2024, 2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016
),
company = c(
rep("Pantone", 11),
rep("Benjamin Moore", 11),
rep("Sherwin-Williams", 11)
),
# RGB Values (Approximate)
R = c(
# Pantone (240, 164, 255, 190, 102, 196, 15, 255, 95, 136, 196),
# BM (74, 170, 91, 210, 163, 100, 235, 175, 175, 95, 243),
# SW (188, 163, 180, 174, 149, 84, 47, 209, 25, 140, 237)
# Filling full vectors for copy-paste convenience:
240, 164, 255, 190, 102, 196, 15, 255, 95, 136, 196, # Pantone
74, 170, 91, 210, 163, 100, 235, 175, 175, 95, 243, # BM
188, 163, 180, 174, 149, 84, 47, 209, 25, 140, 237 # SW
),
G = c(
238, 120, 190, 52, 103, 186, 76, 111, 75, 176, 185, # Pantone
65, 140, 108, 90, 170, 120, 225, 180, 45, 80, 244, # BM
166, 175, 190, 142, 151, 94, 61, 134, 85, 130, 234 # SW
),
B = c(
233, 100, 152, 85, 171, 114, 129, 97, 139, 75, 205, # Pantone
60, 150, 145, 70, 158, 130, 225, 180, 45, 95, 237, # BM
142, 169, 195, 126, 138, 96, 76, 106, 100, 125, 224 # SW
)
)
# 2. Calculate Distances
# Group by company, sort by year, and calculate Euclidean distance from previous year
df_dist <- colors_ts %>%
group_by(company) %>%
arrange(year) %>%
mutate(
# Lag gives the value of the previous row (previous year)
dist = sqrt(
(R - lag(R))^2 +
(G - lag(G))^2 +
(B - lag(B))^2
)
) %>%
filter(!is.na(dist)) # Remove the first year (2016) since it has no previous year
# 3. Plot
ggplot(df_dist, aes(x = year, y = dist, color = company, group = company)) +
geom_line(size = 1.2) +
geom_point(size = 3) +
scale_x_continuous(breaks = 2017:2026) +
labs(
title = "Volatility of Color Trends (2017-2026)",
subtitle = "Euclidean Distance from Previous Year's Selection",
y = "Magnitude of Change (Distance)",
x = "Year"
) +
theme_minimal() +
theme(legend.position = "bottom")