DataViz.manishdatt.com

Project Gutenberg

Frequency of books in different languages.

By Manish Datt

TidyTuesday data for 2025-06-03

library(tidyverse)

── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.2 ✔ tibble 3.2.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.0.4
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (http://conflicted.r-lib.org/) to force all conflicts to become errors

library(wordcloud)

Loading required package: RColorBrewer

library(RColorBrewer)
library(ISOcodes)
library(scales)

Attaching package: 'scales'

The following object is masked from 'package:purrr':

discard

The following object is masked from 'package:readr':

col_factor

library(magick)

Linking to ImageMagick 6.9.12.98
Enabled features: cairo, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp
Disabled features: fontconfig, x11

gutenberg_authors <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-06-03/gutenberg_authors.csv')

Rows: 26077 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (4): author, alias, wikipedia, aliases
dbl (3): gutenberg_author_id, birthdate, deathdate

ℹ Use spec() to retrieve the full column specification for this data.
ℹ Specify the column types or set show_col_types = FALSE to quiet this message.

gutenberg_languages <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-06-03/gutenberg_languages.csv')

Rows: 76205 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): language
dbl (2): gutenberg_id, total_languages

ℹ Use spec() to retrieve the full column specification for this data.
ℹ Specify the column types or set show_col_types = FALSE to quiet this message.

gutenberg_metadata <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-06-03/gutenberg_metadata.csv')

Rows: 79491 Columns: 8
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): title, author, language, gutenberg_bookshelf, rights
dbl (2): gutenberg_id, gutenberg_author_id
lgl (1): has_text

ℹ Use spec() to retrieve the full column specification for this data.
ℹ Specify the column types or set show_col_types = FALSE to quiet this message.

gutenberg_subjects <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-06-03/gutenberg_subjects.csv')

Rows: 255312 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): subject_type, subject
dbl (1): gutenberg_id

ℹ Use spec() to retrieve the full column specification for this data.
ℹ Specify the column types or set show_col_types = FALSE to quiet this message.

glimpse(gutenberg_authors)

Rows: 26,077
Columns: 7
$ gutenberg_author_id 1, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1…
$ author "United States", "Lincoln, Abraham", "Henry, Patri…
$ alias "U.S.A.", NA, NA, NA, "Dodgson, Charles Lutwidge",…
$ birthdate NA, 1809, 1736, 1849, 1832, NA, 1819, 1860, NA, 18…
$ deathdate NA, 1865, 1799, 1931, 1898, NA, 1891, 1937, NA, 18…
$ wikipedia "https://en.wikipedia.org/wiki/United_States", "ht…
$ aliases "U.S.A.", "United States President (1861-1865)/Lin…

glimpse(gutenberg_languages)

Rows: 76,205
Columns: 3
$ gutenberg_id 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,…
$ language "en", "en", "en", "en", "en", "en", "en", "en", "en", …
$ total_languages 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …

glimpse(gutenberg_metadata)

Rows: 79,491
Columns: 8
$ gutenberg_id 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14,…
$ title "The Declaration of Independence of the United Sta…
$ author "Jefferson, Thomas", "United States", "Kennedy, Jo…
$ gutenberg_author_id 1638, 1, 1666, 3, 1, 4, NA, 3, 3, NA, 7, 7, 7, 7, …
$ language "en", "en", "en", "en", "en", "en", "en", "en", "e…
$ gutenberg_bookshelf "Politics/American Revolutionary War/United States…
$ rights "Public domain in the USA.", "Public domain in the…
$ has_text TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TR…

glimpse(gutenberg_subjects)

Rows: 255,312
Columns: 3
$ gutenberg_id 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, …
$ subject_type "lcsh", "lcsh", "lcc", "lcc", "lcsh", "lcsh", "lcc", "lcc…
$ subject "United States -- History -- Revolution, 1775-1783 -- Sou…

lang_counts <- gutenberg_languages %>% 
  group_by(language) %>%
  summarise(total_languages = sum(total_languages), .groups = 'drop') %>%
  arrange(desc(total_languages)) %>% 
  left_join(ISO_639_2, by = c("language" = "Alpha_2")) %>% 
  select(language, Name, total_languages)
glimpse(lang_counts)

Rows: 70
Columns: 3
$ language "en", "fr", "fi", "de", "it", "nl", "es", "pt", "hu", …
$ Name "English", "French", "Finnish", "German", "Italian", "…
$ total_languages 60875, 4019, 3314, 2363, 1061, 1053, 917, 651, 610, 45…

lang_counts2 <- lang_counts %>% 
  filter(Name != "English")
png("word_cloud.png", width = 4, height = 4, units = "in", res = 300, bg = "black")
p1 <- wordcloud(words = lang_counts2$Name, freq = lang_counts2$total_languages,
          min.freq = 0,
          random.order = FALSE,
          colors = brewer.pal(9, "Pastel1"))
dev.off()

png
2

lang_counts %>% 
  filter(Name != "English") %>% 
  arrange(desc(total_languages)) %>% 
  slice(1:10) %>% 
  ggplot(aes(x = total_languages, y =reorder(Name, total_languages))) +
  geom_col(alpha=0) +
  geom_text(aes(label = comma(total_languages), x=70), color = "grey", hjust=1) +
  theme_minimal() +
  scale_y_discrete(labels = function(x) paste0(x, ":"))+
  coord_cartesian(xlim = c(0, 100)) +
  theme(axis.title = element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        axis.text.y = element_text(color = "grey"),
        axis.line = element_blank(),
        panel.grid = element_blank(),
        plot.margin = margin(75, 0, 75, 0))
ggsave("plot1.png", width = 1.75, height = 4, units = "in", bg="black")
img1 <- image_read("word_cloud.png")
img2 <- image_read("plot1.png")
combined <- image_append(c(img1, img2), stack = FALSE)
#image_write(combined, "combined.png")

title_text <- paste("In Project Gutenberg, ", comma(lang_counts$total_languages[1]), " out of ", comma(dim(gutenberg_languages)[1]), "books are in English. The word cloud is based on the book counts in different languages, excluding English. Counts for top ten languages are shown on the right.")
title_text <- paste(strwrap(title_text, width = 75), collapse = "\n")
title_image <- image_blank(width = image_info(combined)$width,
                           height = 160, # adjust height as needed
                           color = "black") %>%
  image_annotate(text = title_text,
                 size = 40, # adjust font size
                 color = "grey",
                 gravity = "center")

final_image <- image_composite(combined, title_image, offset = "+0+0")
image_write(final_image, "combined_with_title.png")