library(tidyverse)
library(lubridate)
library(scales)
library(ggplot2)
# Load TidyTuesday helpers
# here::here() には依存しない。rprojroot の新しい版で is_quarto_project が
# 入ったため、_quarto.yml をルート標識として扱い、リポジトリ root ではなく
# scripts/by_timeSeries/quarto を返すようになった(helper は repo root の
# config/R/ にあるので届かない)。版に依存しないよう、cwd から上へ探す。
.chokotto_find_up <- function(rel, max_depth = 8L) {
d <- normalizePath(".", winslash = "/")
for (i in seq_len(max_depth)) {
p <- file.path(d, rel)
if (file.exists(p)) return(p)
parent <- dirname(d)
if (identical(parent, d)) break
d <- parent
}
stop("not found while walking up from ", normalizePath("."), ": ", rel)
}
source(.chokotto_find_up(file.path("config", "R", "tidytuesday_helpers.R")))TidyTuesday: 2025 Market Events - S&P500 vs Nikkei 225
Overview
This week’s TidyTuesday explores the major market events of 2025, visualizing how the S&P 500 and Nikkei 225 responded to key events like tariff announcements, Fed rate decisions, and geopolitical tensions.
The visualization features:
- Rebased line chart: S&P 500 and Nikkei 225 rebased to 100 on each market’s first trading day of 2025
- Trend shading: Green for uptrends, red for downtrends
- Event markers: Vertical lines marking significant market events
Dataset
Source: Index closes from FRED (SP500, NIKKEI225, calendar 2025). Event list and trend periods compiled from Reuters. Data is fixed in data/ by prepare_data.py, so re-rendering does not change the numbers.
# 記事フォルダの data/ だけを読む(prepare_data.py が FRED の 2025 年分を固定している)
events <- read_csv("data/events_2025.csv", show_col_types = FALSE) %>%
mutate(date = as.Date(date))
trends <- read_csv("data/trend_periods_2025.csv", show_col_types = FALSE) %>%
mutate(
start_date = as.Date(start_date),
end_date = as.Date(end_date)
)
# Display events
events %>%
select(date, market, category, event_label) %>%
head(10)# A tibble: 10 × 4
date market category event_label
<date> <chr> <chr> <chr>
1 2025-01-15 US INFLATION CPI Cooled
2 2025-01-24 JP MONETARY_POLICY BOJ Hike 0.5%
3 2025-01-29 US MONETARY_POLICY FOMC Hold
4 2025-03-03 US TARIFF Tariff Shock
5 2025-04-03 BOTH TARIFF Reciprocal Tariffs
6 2025-04-04 US TARIFF Tariff Shock Week
7 2025-04-08 JP TARIFF Nikkei Rebound
8 2025-04-09 BOTH TARIFF 90-Day Pause
9 2025-04-10 BOTH TARIFF Post-Pause Reversal
10 2025-05-12 BOTH TARIFF US-China Truce
read_index <- function(path, name) {
read_csv(path, show_col_types = FALSE) %>%
mutate(date = as.Date(date)) %>%
arrange(date) %>%
transmute(
date,
index = name,
close = value,
daily_change = (close / lag(close) - 1) * 100,
rebased = close / first(close) * 100
)
}
# 休場日は市場ごとに違うので、日付で揃えずに縦持ちにする
index_long <- bind_rows(
read_index("data/sp500.csv", "S&P 500"),
read_index("data/nikkei225.csv", "Nikkei 225")
)
index_data <- index_long %>%
filter(index == "S&P 500") %>%
select(date, sp500 = close)
index_long %>%
group_by(index) %>%
summarise(
first_day = min(date),
last_day = max(date),
trading_days = n(),
ytd_change_pct = round((last(close) / first(close) - 1) * 100, 2)
)# A tibble: 2 × 5
index first_day last_day trading_days ytd_change_pct
<chr> <date> <date> <int> <dbl>
1 Nikkei 225 2025-01-06 2025-12-30 243 28.1
2 S&P 500 2025-01-02 2025-12-31 250 16.6
Exploratory Analysis
Let’s examine the trend periods and major events:
# US Trends
trends %>%
filter(market == "US") %>%
select(start_date, end_date, trend_type, trigger_event)# A tibble: 8 × 4
start_date end_date trend_type trigger_event
<date> <date> <chr> <chr>
1 2025-01-01 2025-03-02 UP Post-2024 Rally
2 2025-03-03 2025-04-08 DOWN Tariff Shock
3 2025-04-09 2025-04-09 UP 90-Day Pause
4 2025-04-10 2025-05-12 DOWN Tariff Uncertainty
5 2025-05-13 2025-09-16 UP US-China Truce
6 2025-09-17 2025-11-12 UP Fed Easing Cycle
7 2025-11-13 2025-12-09 DOWN Rate Cut Doubts
8 2025-12-10 2025-12-31 UP Year-End Rally
# Major events by category
events %>%
count(category, sort = TRUE)# A tibble: 5 × 2
category n
<chr> <int>
1 TARIFF 7
2 MONETARY_POLICY 6
3 RATES 3
4 INFLATION 2
5 GEOPOLITICAL 1
Visualization
Main Chart: S&P 500 with Events and Trends
# Filter US trends
us_trends <- trends %>% filter(market == "US")
# Filter US/BOTH events
# 当日の騰落率は手入力の値ではなく、FRED の終値から計算する
sp500_moves <- index_long %>%
filter(index == "S&P 500") %>%
select(date, sp500_move = daily_change)
us_events <- events %>%
filter(market %in% c("US", "BOTH")) %>%
inner_join(sp500_moves, by = "date")
# Create main visualization
p <- ggplot() +
# Trend shading
geom_rect(
data = us_trends,
aes(
xmin = start_date, xmax = end_date,
ymin = -Inf, ymax = Inf,
fill = trend_type
),
alpha = 0.15
) +
# S&P 500 line
geom_line(
data = index_data,
aes(x = date, y = sp500),
color = "#2563eb",
linewidth = 0.8
) +
# Event markers
geom_vline(
data = us_events,
aes(xintercept = date),
linetype = "dashed",
color = "#64748b",
alpha = 0.7
) +
# Event labels
geom_text(
data = us_events,
aes(x = date, y = Inf, label = event_label),
angle = 90, hjust = 1.1, vjust = 0.5,
size = 2.5, color = "#334155"
) +
# Styling
scale_fill_manual(
values = c("UP" = "#22c55e", "DOWN" = "#ef4444"),
name = "Trend"
) +
scale_x_date(
date_breaks = "1 month",
date_labels = "%b",
expand = c(0.02, 0)
) +
scale_y_continuous(
labels = comma_format(),
expand = c(0.1, 0)
) +
labs(
title = "2025 Market Events: S&P 500",
subtitle = "Trend periods (shaded) and major events (dashed lines)",
x = NULL,
y = "S&P 500 Index",
caption = tt_caption(source = "FRED, Reuters")
) +
theme_minimal(base_size = 12) +
theme(
plot.title = element_text(face = "bold", size = 16),
plot.subtitle = element_text(color = "#64748b", size = 11),
legend.position = "top",
panel.grid.minor = element_blank(),
plot.margin = margin(20, 20, 20, 20)
)
p
S&P 500 vs Nikkei 225
ggplot(index_long, aes(x = date, y = rebased, color = index)) +
geom_hline(yintercept = 100, color = "#94a3b8", linewidth = 0.4) +
geom_line(linewidth = 0.8) +
scale_color_manual(values = c("S&P 500" = "#2563eb", "Nikkei 225" = "#dc2626"), name = NULL) +
scale_x_date(date_breaks = "1 month", date_labels = "%b", expand = c(0.02, 0)) +
labs(
title = "S&P 500 vs Nikkei 225 in 2025",
subtitle = "Closing level rebased to 100 on each market's first trading day",
x = NULL,
y = "Rebased (first day = 100)",
caption = tt_caption(source = "FRED (SP500, NIKKEI225)")
) +
theme_minimal(base_size = 12) +
theme(
plot.title = element_text(face = "bold", size = 16),
plot.subtitle = element_text(color = "#64748b", size = 11),
legend.position = "top",
panel.grid.minor = element_blank()
)
Event Impact Summary
# Bar chart of event-day moves (computed from FRED closes)
us_events %>%
mutate(
direction = ifelse(sp500_move > 0, "Positive", "Negative"),
event_label = fct_reorder(event_label, sp500_move)
) %>%
ggplot(aes(x = event_label, y = sp500_move, fill = direction)) +
geom_col() +
coord_flip() +
scale_fill_manual(values = c("Positive" = "#22c55e", "Negative" = "#ef4444")) +
labs(
title = "S&P 500 Daily Change on Event Days",
subtitle = "Close-to-close change on the event date, 2025",
x = NULL,
y = "Daily Change (%)",
fill = NULL,
caption = tt_caption(source = "FRED (SP500), Reuters")
) +
theme_minimal() +
theme(
plot.title = element_text(face = "bold"),
legend.position = "none"
)
Key Findings
Tariff Shock (April 2025): The S&P 500 fell -4.84% on the reciprocal tariff announcement (April 3) and a further -5.97% the next day, the largest single-day drop of the year. It then rallied +9.52% when the 90-day pause was announced (April 9). The Nikkei 225 took its biggest hit on the following Monday (-7.83% on April 7).
Fed Easing Cycle: Three rate cuts (September, October, December) supported a gradual uptrend in the second half of 2025.
Geopolitical Events: The Israel-Iran escalation in June triggered a brief risk-off period with oil spiking +7%.
Full-Year Result: Despite the April drawdown, the S&P 500 ended 2025 up 16.65% and the Nikkei 225 up 28.07% from their first trading days.
This post is part of the TidyTuesday weekly data visualization project.