---
freeze: true
title: "Bob's Burgers: Questioning Nature of Dialogue"
subtitle: "Questions dominate dialogue, with rare exceptions (highlighted). Red circles (○) indicate episodes where exclamations exceed questions"
author: "Steven Ponce"
description: "Questions versus exclamations in Bob's Burgers dialogue, highlighting episodes where exclamations win. Built in R."
date: "2024-11-18"
categories: ["TidyTuesday", "2024"]
image: "thumbnails/tt_2024_47.png"
format:
html:
toc: true
toc-depth: 5
code-link: true
code-fold: true
code-tools: true
code-summary: "Show code"
editor_options:
chunk_output_type: inline
execute:
error: false
message: false
warning: false
eval: true
# share:
# permalink: "https://stevenponce.netlify.app/data_visualizations.png"
# linkedin: true
# twitter: true
# email: true
---
{#fig-1}
### <mark> __Steps to Create this Graphic__ </mark>
#### 1. Load Packages & Setup
```{r}
#| label: load
#| warning: false
## 1. LOAD PACKAGES & SETUP ----
if (!require("pacman")) install.packages("pacman")
pacman::p_load(
tidyverse, # Easily Install and Load the 'Tidyverse'
ggtext, # Improved Text Rendering Support for 'ggplot2'
showtext, # Using Fonts More Easily in R Graphs
janitor, # Simple Tools for Examining and Cleaning Dirty Data
skimr, # Compact and Flexible Summaries of Data
scales, # Scale Functions for Visualization
glue, # Interpreted String Literals
here, # A Simpler Way to Find Your Files
marquee # Markdown Parser and Renderer for R Graphic
)
### |- figure size ----
camcorder::gg_record(
dir = here::here("temp_plots"),
device = "png",
width = 10,
height = 10,
units = "in",
dpi = 320
)
### |- resolution ----
showtext_opts(dpi = 320, regular.wt = 300, bold.wt = 800)
```
#### 2. Read in the Data
```{r}
#| label: read
#| include: true
#| eval: true
#| warning: false
tt <- tidytuesdayR::tt_load(2024, week = 47)
episode_metrics <- tt$episode_metrics|> clean_names()
tidytuesdayR::readme(tt)
rm(tt)
```
#### 3. Examine the Data
```{r}
#| label: examine
#| include: true
#| eval: true
#| results: 'hide'
#| warning: false
glimpse(episode_metrics)
skim(episode_metrics)
```
#### 4. Tidy Data
```{r}
#| label: tidy
#| warning: false
### |- tidy data ----
### |- plot data ----
plot_data <- episode_metrics |>
pivot_longer(
cols = c(question_ratio, exclamation_ratio),
names_to = "ratio_type", values_to = "value"
) |>
mutate(
ratio_type = case_when(
ratio_type == "question_ratio" ~ "Questions",
ratio_type == "exclamation_ratio" ~ "Exclamations"
)
)
### |- highlight data ----
highlight_data <- plot_data |>
pivot_wider(names_from = ratio_type, values_from = value) |>
filter(Exclamations > Questions)
```
#### 5. Visualization Parameters
```{r}
#| label: params
#| include: true
#| warning: false
### |- plot aesthetics ----
bkg_col <- "#f5f5f2"
title_col <- "gray20"
subtitle_col <- "gray20"
caption_col <- "gray30"
text_col <- "gray30"
col_palette <- c("Questions" = "#2171b5", "Exclamations" = "#ef8a62")
### |- titles and caption ----
# icons
tt <- str_glue("#TidyTuesday: { 2024 } Week { 47 } • Source: bobsburgersR R Package<br>")
li <- str_glue("<span style='font-family:fa6-brands'></span>")
gh <- str_glue("<span style='font-family:fa6-brands'></span>")
bs <- str_glue("<span style='font-family:fa6-brands'> </span>")
# text
title_text <- str_glue("Bob's Burgers: Questioning Nature of Dialogue")
subtitle_text <- "Questions dominate dialogue (15-20%), with rare exceptions in early seasons (highlighted)\n\n
Red circles ({#FF0000 **○**}) indicate episodes where {#ef8a62 **_exclamations_**} exceed {#2171b5 **_questions_**}, more common in seasons 1-6"
caption_text <- str_glue("{tt} {li} stevenponce • {bs} sponce1 • {gh} poncest • #rstats #ggplot2")
### |- fonts ----
font_add("fa6-brands", here::here("fonts/6.6.0/Font Awesome 6 Brands-Regular-400.otf"))
font_add_google("Oswald", regular.wt = 400, family = "title")
font_add_google("Source Sans Pro", family = "text")
font_add_google("Roboto Mono", family = "numbers")
font_add_google("Noto Sans", regular.wt = 400, family = "caption")
showtext_auto(enable = TRUE)
### |- plot theme ----
theme_set(theme_minimal(base_size = 14, base_family = "text"))
theme_update(
plot.title.position = "plot",
plot.caption.position = "plot",
legend.position = "plot",
plot.background = element_rect(fill = bkg_col, color = bkg_col),
panel.background = element_rect(fill = bkg_col, color = bkg_col),
plot.margin = margin(t = 10, r = 20, b = 10, l = 20),
axis.title.x = element_text(margin = margin(10, 0, 0, 0), size = rel(1.1),
color = text_col, family = "text", face = "bold", hjust = 0.5),
axis.title.y = element_text(margin = margin(0, 10, 0, 0), size = rel(1.1),
color = text_col, family = "text", face = "bold", hjust = 0.5),
axis.text = element_text(size = rel(0.6), color = text_col, family = "numbers"),
axis.ticks.x = element_line(color = text_col),
axis.line.x = element_line(color = "#252525", linewidth = .2),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
panel.grid.major.y = element_line(color = "grey90", linewidth = 0.2),
panel.spacing.x = unit(2, "lines"),
panel.spacing.y = unit(2, "lines"),
strip.text = element_text(size = rel(1), face = "bold", margin = margin(b = 10), family = "text"),
)
```
#### 6. Plot
```{r}
#| label: plot
#| warning: false
### |- plot ----
p <- plot_data |>
ggplot(aes(x = episode, y = value * 100, color = ratio_type)) +
# Geoms
geom_line(aes(alpha = ratio_type), linewidth = 1) +
geom_point(aes(alpha = ratio_type), size = 1.3) +
geom_point(
data = highlight_data,
aes(y = Exclamations * 100),
color = "red", size = 4, shape = 1, stroke = 0.8
) +
# Scales
scale_x_continuous() +
scale_y_continuous(labels = scales::label_number(suffix = "%")) +
scale_color_manual(values = col_palette) +
scale_alpha_manual(values = c("Questions" = 1, "Exclamations" = 0.3)) +
guides(alpha = "none") +
coord_cartesian(clip = "off") +
# Labs
labs(
x = "Episode Number",
y = "Proportion of Total Sentences",
color = "Sentence Type",
title = title_text,
subtitle = subtitle_text,
caption = caption_text
) +
# Facet
facet_wrap(~season,
labeller = label_both
) +
# Theme
theme(
plot.title = element_text(
size = rel(2.3),
family = "title",
face = "bold",
color = title_col,
margin = margin(t = 5, b = 5)
),
plot.subtitle = element_marquee(
size = rel(1.05),
family = "subtitle",
color = title_col,
lineheight = 1.1,
margin = margin(t = 5, b = 15)
),
plot.caption = element_markdown(
size = rel(.65),
family = "caption",
color = caption_col,
lineheight = 0.65,
hjust = 0.5,
halign = 0.5,
margin = margin(t = 10, b = 5)
),
)
```
#### 7. Save
```{r}
#| label: save
#| warning: false
### |- plot image ----
# Save the plot as PNG
ggsave(
filename = here::here("data_visualizations/TidyTuesday/2024/tt_2024_47.png"),
plot = p,
width = 10, height = 10, units = "in", dpi = 320
)
### |- plot thumbnail----
magick::image_read(here::here("data_visualizations/TidyTuesday/2024/tt_2024_47.png")) |>
magick::image_resize(geometry = "400") |>
magick::image_write(here::here("data_visualizations/TidyTuesday/2024/thumbnails/tt_2024_47.png"))
```
#### 8. Session Info
::: {.callout-tip collapse="true"}
##### Expand for Session Info
```{r, echo = FALSE}
#| eval: true
#| warning: false
sessionInfo()
```
:::
#### 9. GitHub Repository
::: {.callout-tip collapse="true"}
##### Expand for GitHub Repo
[Access the GitHub repository here](https://github.com/poncest/personal-website/)
:::