Loading packages, data, fonts and difining colors

# Loading packages
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.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── 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)

# Loading data
tuesdata <- tidytuesdayR::tt_load(2023, week = 35)
## --- Compiling #TidyTuesday Information for 2023-08-29 ----
## --- There are 2 files available ---
## --- Starting Download ---
## 
## 	Downloading file 1 of 2: `fair_use_cases.csv`
## 	Downloading file 2 of 2: `fair_use_findings.csv`
## --- Download complete ---
fair_use_cases <- tuesdata$fair_use_cases
fair_use_findings <- tuesdata$fair_use_findings

# Loading fonts and colors
font_add_google("Montserrat", "montserrat")
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()
bg <- "white"
col1 <- "black"

Text generation

# text creation
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>")
hash <- glue("<span style='color:{col1};font-family:fa-solid;'>&#x23;</span>")
data <- glue("<span style='color:{col1};font-family:fa-solid;'>&#xf1c0;</span>")
space <- glue("<span style='color:{bg}'>-</span>")
space2 <- glue("<span style='color:{bg}'>--</span>") # can't believe I'm doing this

t <- "<b>Copyright: Fair use founds by court</b>"
s <- "Tidy Tuesday 2023 | Week 35"
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}U.S. Copyright Office Fair Use Index{space2}
 	{space2}{hash}{space2}tidytuesday")

Plot

ggplot(data = fair_use_cases, aes(x = fair_use_found,fill = fair_use_found, color = fair_use_found)) +
geom_bar(show.legend = F) +
facet_wrap(~court, scales="free_y") +
theme_bw() +
labs(title = t, subtitle = s, caption = cap) +
theme(strip.text = element_text(size = 8, family = "montserrat"),
plot.margin = margin(10, 10, 10, 10),
plot.title = element_markdown(size = 20, hjust = 0, lineheight = 1.3, family = "montserrat"),
plot.subtitle = element_markdown(size = 18, hjust = 0, lineheight = 1.3, family = "montserrat"),
plot.caption = element_markdown(size = 12, hjust = 0, lineheight = 1.3, family = "montserrat"),
axis.text = element_text(size = 8, family = "montserrat"),
axis.title = element_blank()
)
Data visualization representing fair use cases found by courts. The plot uses bar charts and facets to display the distribution of fair use findings across different courts. The x-axis represents the fair use findings, and the y-axis represents the count or percentage of cases. Additional information, including the chart title 'Copyright: Fair use founds by court,' subtitle 'Tidy Tuesday 2023 | Week 35,' and source attribution, is provided in the caption.

R Code Documentation

Overview

This R script is designed to create png output that visualizes data related to fair use cases found by courts. It utilizes several R packages and custom fonts to customize the appearance of the plot and text elements. The script fetches data for Tidy Tuesday 2023, Week 35, and uses the `ggplot2` package to create a bar chart with facet wrapping. The chart's title, subtitle, and caption are styled using custom fonts and icons.

Packages Used

  • `tidyverse`: A collection of data manipulation packages, including `ggplot2` for data visualization.
  • `tidytuesdayR`: A package for loading Tidy Tuesday datasets.
  • `showtext`: A package for using custom fonts in plots and text.
  • `glue`: A package for string interpolation and formatting.
  • `ggtext`: A package for styling text in `ggplot2` plots.

Loading Data

  • The script loads data for Tidy Tuesday 2023, Week 35, specifically the `fair_use_cases` and `fair_use_findings` datasets from the Tidy Tuesday repository.

Loading Fonts and Colors

  • Custom fonts are added using the `showtext` package.
  • Three custom fonts are loaded: 'Montserrat', 'Font Awesome 6 Free-Regular', 'Font Awesome 6 Brands-Regular', and 'Font Awesome 6 Free-Solid'.
  • Background color (`bg`) is set to white, and primary text color (`col1`) is set to black.

Text Creation

  • Custom text strings are created using the `glue` package and styled with custom fonts and colors. These strings include icons for Twitter, Mastodon, links, data, and hashtags.
  • The `space` and `space2` strings are used to create spaces with custom background colors.

Plot Creation

  • A bar chart is created using `ggplot2` with the `fair_use_cases` dataset.
  • The `x` aesthetic is set to `fair_use_found`, and the bars are filled and colored based on the same variable.
  • Facets are wrapped by the `court` variable with free y-scales.
  • The plot is styled with a black-and-white theme, custom fonts, and custom font sizes.
  • The title, subtitle, and caption are set with the previously created text strings.
  • Various theme elements such as text size, margin, and title alignment are customized.

Output

The output of this script is a png file that contains the styled bar chart along with the specified title, subtitle, and caption. The chart includes custom icons and fonts to enhance its appearance and readability. This HTML file can be easily shared or embedded in web pages for data visualization purposes.