This code creates a visually appealing graphic output with a boxplot showcasing the educational scores of English towns and cities by region. The use of Font Awesome icons and custom text formatting adds a unique touch to the title, subtitle, and caption.

The Code

# load libraries
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── 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(tidytuesdayR)
library(showtext)
## Lade nötiges Paket: sysfonts
## Lade nötiges Paket: showtextdb
library(glue)
library(ggtext)

# load data
tuesdata <- tidytuesdayR::tt_load(2024, week = 4)
## --- Compiling #TidyTuesday Information for 2024-01-23 ----
## --- There is 1 file available ---
## --- Starting Download ---
## 
## 	Downloading file 1 of 1: `english_education.csv`
## --- Download complete ---
english_education <- tuesdata$english_education

# load fonts
font_add('fa-reg', 'c:/Users/info/OneDrive/Dokumente/fonts/Font Awesome 6 Free-Regular-400.otf')
font_add('fa-brands', 'c:/Users/info/OneDrive/Dokumente/fonts/Font Awesome 6 Brands-Regular-400.otf')
font_add('fa-solid', 'c:/Users/info/OneDrive/Dokumente/fonts/Font Awesome 6 Free-Solid-900.otf')
showtext_auto()

# define colors
bg <- "white"
col1 <- "darkgrey"

# Text creation using Font Awesome icons and custom styles
twitter <- glue("<span style='color:{col1};font-family:fa-brands;'>&#xf099;</span>")
mastodon <- glue("<span style='color:{col1};font-family:fa-brands;'>&#xf4f6;</span>")
link <- glue("<span style='color:{col1};font-family:fa-solid;'>&#xf0c1;</span>")
data <- glue("<span style='color:{col1};font-family:fa-solid;'>&#xf1c0;</span>")
hash <- glue("<span style='color:{col1};font-family:fa-solid;'>&#x23;</span>")
space <- glue("<span style='color:{bg}'>-</span>")
space2 <- glue("<span style='color:{bg}'>--</span>") # can't believe I'm doing this

# Title, subtitle, and caption text
t <- "<b>Educational Score of English towns and cities by region</b>"
s <- glue("Tidy Tuesday 2024 | Week 4")
cap <- glue("{twitter}{space2}@web_design_fh{space2} 
	{space2}{mastodon}{space2}@frankhaenel @fosstodon.org{space2}
	{space2}{link}{space}{space2}www.frankhaenel.de<br>
	{data}{space2}The{space2}UK{space2}Office{space2}for{space2}National{space2}Statistics{space2}
	{space2}{hash}{space2}tidytuesday")

# Plotting the educational scores using ggplot2
english_education %>% select(rgn11nm,education_score) %>% na.omit() %>%
  ggplot(aes(x=education_score, y = rgn11nm, color = rgn11nm,fill=rgn11nm)) +
  geom_boxplot(show.legend = F, alpha = 0.5, outlier.shape = NA) +
  geom_jitter(show.legend = F) +
  scale_color_manual(values = c(thematic::okabe_ito(),"grey")) +
  scale_fill_manual(values = c(thematic::okabe_ito(),"grey")) +
  facet_wrap(~rgn11nm,scales = "free_y") +
  theme(
    axis.title.y = element_blank(),
    axis.text.y = element_blank(),
    plot.title = element_markdown(hjust = 0.5, lineheight = 1.3),
    plot.subtitle = element_markdown(hjust = 0.5, lineheight = 1.3),
    plot.caption = element_markdown(hjust = 0, lineheight = 1.3)
  ) +
  labs(title = t, subtitle = s, caption = cap, x = "Education Score")
An artistic polar bar chart comparing audio metrics in Taylor Swift's albums, featuring danceability, energy, and other attributes. The chart showcases a unique color palette and symbol-enhanced labels.

R Code Documentation

This R code generates an output that includes a boxplot visualization of the educational scores of English towns and cities by region. The code utilizes various R packages for data manipulation, visualization, and font handling. Below is a detailed explanation of the code.

Libraries Used

  • tidyverse: Used for data manipulation and visualization.
  • tidytuesdayR: Enables access to TidyTuesday datasets.
  • showtext: Facilitates working with fonts in plots.
  • glue: Used for text formatting.
  • ggtext: Enhances text formatting in ggplot2.

Load Data

The code loads data from the TidyTuesday dataset for the year 2024 and week 04. It fetches information about English towns and cities from the dataset.

Load Fonts and Define Colors

Custom fonts are loaded to enhance text appearance, and specific color codes are defined for use in visualizations. These fonts and colors add a unique style to the chart.

Define Title

The title and subtitle for the chart are defined using custom fonts and symbols. These elements contribute to the chart's aesthetics and provide context for the visualization.

Additional Information

The chart is accompanied by a caption that includes contact information and references to external resources, further enhancing its informativeness and usability.