Digits of pi

Author

Jo Hardin

Published

March 24, 2026

Code
library(tidyverse) # ggplot, lubridate, dplyr, stringr, readr...
library(praise)

One Million Digits of Pi

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:

  • Advanced mathematical research
  • Testing computational algorithms
  • Statistical analysis of number patterns
  • Educational purposes and demonstrations

“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.

  • Where does your birthday first appear in π?
  • Are the digits of π uniformly distributed across 0–9?
  • What patterns or runs of repeated digits occur in the first million digits?
  • How can we visualize π creatively (spirals, radial plots, or color-coded art)?
  • Does each digit appear exactly 1/10 of the time, or are some more common than others?
  • Does the frequency distribution change as you use more digits — does it converge to uniform?
  • At what position does the distribution first “stabilise” around 10% each?

The Data

Code
pi_digits <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2026/2026-03-24/pi_digits.csv')
Code
pi_digits |> 
  ggplot() + 
  geom_bar(aes(x = digit))

Code
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>
Code
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
Code
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)

Each day of the year is assessed for how many times it shows up in the first million digits of pi. The plot is a bar chart where the height of bar represents the number of instances, but the plot has been transformed into polar coordinates. The bars have been colored by month. Unsurprisingly, there are no real patterns to which days show up more or less often in the first million digits of pi.

Each spoke of the wheel represents a particular day of the year. The length of the spoke is the number of times that day shows up in the first million digits of pi.
Code
praise()
[1] "You are cat's pajamas!"