library(tRakt)
library(tibble) # For glimpse()

Step 2: Use the ID

Use the trakt ID (recommended over other IDs) for subsequent API calls.
In this case, we’ll use seasons_summary() to get data for all seasons of the show, while also getting an additional list-column containing all episode data, which includes user ratings.

seasons <- seasons_summary(show_info$trakt, extended = "full", episodes = TRUE)
glimpse(seasons)
#> Rows: 9
#> Columns: 13
#> $ season         <int> 1, 2, 3, 4, 5, 6, 7, 8, 9
#> $ rating         <dbl> 8.37594, 8.38378, 8.35151, 8.38849, 8.48032, 7.43518, …
#> $ votes          <int> 266, 185, 165, 139, 127, 108, 102, 93, 128
#> $ episode_count  <int> 24, 24, 24, 24, 24, 24, 24, 24, 12
#> $ aired_episodes <int> 24, 24, 24, 24, 24, 24, 24, 24, 12
#> $ title          <chr> "Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6", …
#> $ overview       <chr> "The first season of the television series 24, titled …
#> $ first_aired    <dttm> 2001-11-06 05:00:00, 2002-10-29 05:00:00, 2003-10-28 …
#> $ network        <chr> "FOX", "FOX", "FOX", "FOX", "FOX", "FOX", "FOX", "FOX"…
#> $ episodes       <list> [<tbl_df[24 x 16]>, <tbl_df[24 x 16]>, <tbl_df[24 x 1…
#> $ trakt          <chr> "6262", "6263", "6264", "6265", "6266", "6267", "6268"…
#> $ tvdb           <chr> "10063", "10064", "10065", "10066", "10067", "16794", …
#> $ tmdb           <chr> "5845", "5846", "5847", "5848", "5849", "5850", "5851"…

Step 3: Tidying up

We’re interested in the episodes list-column, which needs unnesting. In this case we can simply use dplyr::bind_rows to take the list of tbls that is seasons$episodes and basically rbind them all together, meaning the result is a tibble of the episode data we care about.

library(dplyr)

episodes <- bind_rows(seasons$episodes)
glimpse(episodes)
#> Rows: 204
#> Columns: 16
#> $ season                 <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
#> $ episode                <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,…
#> $ title                  <chr> "12:00 A.M. - 1:00 A.M.", "1:00 A.M. - 2:00 A.…
#> $ episode_abs            <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
#> $ overview               <chr> "It is California Presidential Primary Day in …
#> $ rating                 <dbl> 7.77041, 7.80720, 7.79247, 7.80223, 7.78069, 7…
#> $ votes                  <int> 1433, 1084, 930, 895, 839, 812, 791, 792, 772,…
#> $ comment_count          <int> 4, 2, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 2…
#> $ first_aired            <dttm> 2001-11-06 05:00:00, 2001-11-13 05:00:00, 200…
#> $ updated_at             <dttm> 2020-04-28 08:11:40, 2020-04-28 09:34:32, 202…
#> $ available_translations <list> [<"ar", "bg", "bs", "cs", "da", "de", "el", "…
#> $ runtime                <int> 42, 43, 44, 43, 43, 44, 44, 44, 44, 44, 44, 44…
#> $ trakt                  <chr> "146247", "146248", "146249", "146250", "14625…
#> $ tvdb                   <chr> "189255", "189256", "189257", "189258", "18925…
#> $ imdb                   <chr> "tt0502165", "tt0502167", "tt0502169", "tt0502…
#> $ tmdb                   <chr> "972745", "972752", "972753", "134397", "13439…

Step 4: Graph!

Now we have our episode data in a tidy form, might as well look at it.

library(ggplot2)

ggplot(data = episodes, aes(x = episode, y = rating, color = votes)) +
  geom_point(size = 3) +
  facet_wrap(~season, nrow = 1, labeller = label_both, scales = "free_x") +
  scale_x_continuous(breaks = scales::pretty_breaks()) +
  scale_y_continuous(breaks = seq(0, 10, .5), minor_breaks = seq(0, 10, .25), limits = c(7, 9)) +
  scale_color_viridis_c() +
  labs(title = "24: Episode Ratings on trakt.tv",
       subtitle = "Episode ratings by trakt.tv users by season",
       x = "Episode Number", y = "Rating (0-10)", color = "# of Votes",
       caption = "jemus42.github.io/tRakt") +
  theme_minimal() +
  theme(legend.position = "bottom",
        axis.text.x = element_text(size = rel(.6)))