Code
library(tidyverse) # ggplot, lubridate, dplyr, stringr, readr...
library(praise)library(tidyverse) # ggplot, lubridate, dplyr, stringr, readr...
library(praise)This week we’re exploring the digits of π with a dataset submission in celebration of Pi Day (March 14). The dataset contains the first one million digits of π, beginning with 3.14159 …, collected from publicly available sources and curated for analysis and visualization.
One million digits of Pi represents an incredible achievement in mathematical computation. While we know Pi is infinite and irrational, having access to a million digits allows for:
“Pi is an irrational number, meaning its decimal representation never ends and never settles into a permanent repeating pattern.”” — Eve Andersson, collector of the one million digits dataset
The digits are available from multiple open sources, including:
These files provide the canonical sequence of π digits, starting with 3.14159, and have been tidied into a structured dataset for this week’s challenge.
pi_digits <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2026/2026-03-24/pi_digits.csv')pi_digits |>
ggplot() +
geom_bar(aes(x = digit))pi_digits |>
filter(digit == 1, lead(digit) == 1, lead(digit, n = 2) == 2,
lead(digit, n = 3) == 9, lead(digit, n = 4) == 7,
lead(digit, n = 5) == 3)# A tibble: 0 × 2
# ℹ 2 variables: digit_position <dbl>, digit <dbl>
library(lubridate)
temp <- ymd("2000-01-01") + days(0:365)
bdays <- data.frame(month = month(temp), day = day(temp), temp) |>
mutate(month = ifelse(nchar(month) == 1, paste0("0", month), month),
day = ifelse(nchar(day) == 1, paste0("0",day), day),
bday = paste0(month, day))
pi_days <- pi_digits |>
mutate(vals4 = paste0(digit, lead(digit, n = 1), lead(digit, n = 2),
lead(digit, n = 3)))
join_days <- bdays |>
left_join(pi_days, by = c("bday" = "vals4"))
join_days |>
group_by(bday) |>
summarize(num_bday = n()) |>
arrange((num_bday))# A tibble: 366 × 2
bday num_bday
<chr> <int>
1 0822 78
2 0304 79
3 0523 81
4 0125 82
5 0513 82
6 1211 82
7 0905 83
8 1112 83
9 0203 84
10 0623 84
# ℹ 356 more rows
join_days |>
mutate(month_word = month(temp, label = TRUE)) |>
ggplot() +
geom_bar(aes(x = bday, fill = month_word)) +
coord_polar() +
theme_void() +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank()) +
scale_fill_viridis_d(option = "turbo") +
#scale_fill_brewer(palette = "Paired") +
labs(x = "", y = "", fill = "") +
annotate("text", x = 0, y = 0, label = "π", parse = TRUE,
size = 47, color = "white", alpha = 0.5)praise()[1] "You are cat's pajamas!"