Skip to content

Instantly share code, notes, and snippets.

@tukachev
Created March 31, 2025 20:42
Show Gist options
  • Save tukachev/21bdaefc38f582d05f8c5176fe1fc815 to your computer and use it in GitHub Desktop.
Save tukachev/21bdaefc38f582d05f8c5176fe1fc815 to your computer and use it in GitHub Desktop.
Day of the year with peak cherry tree blossom
library(tidyverse)
library(showtext)
library(ggshadow)
showtext_auto()
showtext_opts(dpi = 300)
font_add_google("Playfair Display", "PD")
font_add_google("Lato", "lato")
df <- read.csv(
"https://ourworldindata.org/grapher/date-of-the-peak-cherry-tree-blossom-in-kyoto.csv?v=1&csvType=full&useColumnShortNames=true"
)
colnames(df) <- c("Entity", "Code", "Year", "MovingAvg", "PeakBlossomDay")
df <- df %>% filter(!is.na(MovingAvg))
latest_year <- max(df$Year)
latest_value <- df %>% filter(Year == latest_year) %>% pull(MovingAvg)
latest_point <- df %>% filter(Year == latest_year) %>% pull(PeakBlossomDay)
lines_data <- data.frame(y = seq(70, 130, 10))
ggplot(df, aes(x = Year)) +
geom_segment(
data = lines_data,
aes(
x = 812,
xend = 2024,
y = y,
yend = y
),
color = "gray90",
linewidth = 0.5,
linetype = "dashed"
) +
geom_point(
aes(y = PeakBlossomDay),
color = "white",
fill = "#f4a7c0",
size = 2.5,
shape = 21,
stroke = 0.3
) +
geom_shadowline(
aes(y = MovingAvg),
color = "#b42f46",
shadowcolour = "white",
size = 0.5,
shadowsize = 1.4
) +
annotate(
"text",
x = latest_year + 10,
y = latest_value,
label = "Twenty-year average",
color = "#b42f46",
size = 3.5,
fontface = "bold",
hjust = 0
) +
annotate(
"text",
x = latest_year + 10,
y = 100,
label = "Day of the year with\npeak cherry tree blossom",
lineheight = 1,
color = "#BE8EA6",
size = 3.5,
fontface = "bold",
hjust = 0
) +
scale_y_continuous(breaks = seq(70, 130, 10), expand = c(0.01, 0)) +
scale_x_continuous(
breaks = c(812, 1000, 1200, 1400, 1600, 1800, 2024),
limits = c(812, latest_year + 400),
expand = c(0.01, 0)
) +
theme_minimal(base_family = "lato") +
labs(
title = "Day of the year with peak cherry tree blossom in Kyoto, Japan",
subtitle = stringr::str_wrap(
"The vertical axis shows the date of peak blossom, expressed as the number of days since 1st January. The timing of the peak cherry blossom is influenced by spring temperatures. Higher temperatures due to climate change have caused the peak blossom to gradually move earlier in the year since the early 20th century...",
82
),
x = NULL,
y = NULL,
caption = "Source: Yasuyuki Aono (2021; 2024) | OurWorldInData.org\nNote: The 20-year average is calculated when there are at least five years with data in the 20-year window.\nYurij Tukachev, april 2025 @weekly_charts"
) +
theme(
plot.title = element_text(
size = 18,
face = "bold",
family = "PD",
color = "black",
margin = margin(b = 10)
),
plot.subtitle = element_text(
size = 14,
color = "gray40",
margin = margin(b = 15)
),
axis.title.y = element_text(size = 14, color = "gray40"),
axis.text = element_text(size = 12, color = "gray40"),
axis.ticks.x = element_line(colour = "gray50"),
axis.ticks.length.x = unit(.2, "cm"),
axis.text.y = element_text(hjust = 1),
plot.margin = margin(20, 15, 20, 15),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.title.position = "plot",
plot.caption.position = "plot",
plot.caption = element_text(
size = 10,
color = "gray70",
lineheight = 1.2,
hjust = 0,
margin = margin(t = 20)
),
plot.background = element_rect(fill = "white", color = NA),
panel.background = element_rect(fill = "white", color = NA)
)
ggsave(
"cherry_tree_blossom.png",
height = 6,
width = 8,
dpi = 300
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment