{datardis} package v.0.0.5

Explore the latest Dr Who episodes

R
Package
Dr Who
Author

Jonathan Kitt

Published

August 22, 2024

Introduction


The {datardis} package includes datasets which provide lists of episodes for the Doctor Who and Torchwood TV series.

The latest version of the package (v.0.0.5) includes the latest episodes :

  • 2023 specials
  • Series 14 (2024)


Installing the package


To install the latest version of the package, use the following command:

# 🔽 INSTALL THE PACKAGE --------------------------------------------------

install.packages("datardis")


Alternatively, you can install the package from GitHub using {devtools} :

devtools::install_github("KittJonathan/datardis")


Loading the packages


First of all, let’s load the packages we’ll be using :

If you don’t have the packages installed, simply use the install.packages("...") function.


# 📦 LOAD THE PACKAGES ----------------------------------------------------

library(tidyverse)
library(showtext)
library(datardis)


Cleaning the data


We use the following code to clean the data:

# 🧹  Clean the data ----

d <- drwho_episodes |> 
  filter(year(first_aired) >= 2023) |> 
  select(episode_number, type, episode_title, first_aired, uk_viewers, duration) |> 
  mutate(uk_viewers = as.numeric(uk_viewers),
         episode_title = case_when(type == "special" ~ paste0(episode_title, " *"),
                                   .default = episode_title),
         episode_title = fct_rev(fct_inorder(episode_title)))

d
# A tibble: 12 × 6
   episode_number type    episode_title          first_aired uk_viewers duration
            <int> <chr>   <fct>                  <date>           <dbl>    <dbl>
 1              1 special The Star Beast *       2023-11-25        7.61       57
 2              2 special Wild Blue Yonder *     2023-12-02        7.14       54
 3              3 special The Giggle *           2023-12-09        6.85       62
 4             NA special The Church on Ruby Ro… 2023-12-25        7.49       55
 5              1 episode Space Babies           2024-05-11        4.01       46
 6              2 episode The Devil's Chord      2024-05-11        3.91       49
 7              3 episode Boom                   2024-05-18        3.58       44
 8              4 episode 73 Yards               2024-05-25        4.06       47
 9              5 episode Dot and Bubble         2024-06-01        3.38       43
10              6 episode Rogue                  2024-06-08        3.52       44
11              7 episode The Legend of Ruby Su… 2024-06-15        3.5        44
12              8 episode Empire of Death        2024-06-22        3.69       54


Creating the plot


We use the following code to create the plot :

# 📊 CREATE THE PLOT ------------------------------------------------------

p <- d |> 
  ggplot() +
  geom_segment(aes(x = 0, xend = uk_viewers,
                   y = episode_title, yend = episode_title),
               colour = "#a6b8c7") +
  geom_point(aes(x = uk_viewers, y = episode_title),
             shape = 21, size = 10, fill = "#00203c", colour = "#a6b8c7") +
  geom_text(aes(x = uk_viewers, y = episode_title, label = uk_viewers),
            hjust = 0.5, family = "Roboto Condensed", size = 10, colour = "white") +
  geom_text(aes(x = 0, y = episode_title, label = episode_title),
            hjust = 0, vjust = -0.5, family = "Roboto Condensed",
            size = 14, colour = "white") +
  geom_segment(aes(x = -0.25, xend = -0.25, y = 9.75, yend = 12.25),
               colour = "#a6b8c7", linewidth = 1) +
  geom_segment(aes(x = -0.25, xend = -0.25, y = 0.75, yend = 9.25),
              colour = "#a6b8c7", linewidth = 1) +
  geom_text(aes(x = -0.5, y = 11, label = "2023 specials"),
            hjust = 0.5, family = "Roboto Condensed", size = 18, colour = "white",
            angle = 90) +
  geom_text(aes(x = -0.5, y = 5, label = "14th series"),
            hjust = 0.5, family = "Roboto Condensed", size = 18, colour = "white",
            angle = 90) +
  labs(title = "Number of UK viewers of Doctor Who episodes (in millions)",
       subtitle = "Special episodes are noted with a *") +
  theme_minimal() +
  theme(axis.title = element_blank(),
        axis.text = element_blank(),
        panel.background = element_rect(colour = "#00203c",
                                        fill = "#00203c"),
        panel.grid = element_blank(),
        plot.background = element_rect(colour = "#00203c",
                                       fill = "#00203c"),
        plot.title = element_text(family = "Roboto Condensed",
                                  colour = "white", size = 50, hjust = 0.5,
                                  margin = margin(t = 5, b = 5)),
        plot.subtitle = element_text(family = "Roboto Condensed",
                                  colour = "white", size = 30, hjust = 0.5))


Save the plot


We use the following code to export the plot to a .png file :

# 💾 EXPORT THE PLOT ------------------------------------------------------

ggsave("img/drwho_viewers.png", p,
       dpi = 320, width = 12, height = 6)


And here’s the result!