TidyTuesday 2020 Week33
Avatar: The last airbender
Preparations
- tvthemes(Nakagawara 2019)
library(tidyverse)
library(tvthemes)
library(ggrepel)
library(flair) #Highlight, Annotate, and Format your R Source Code
Import
avatar <- readr::read_csv(
'https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-08-11/avatar.csv',
col_types = cols(
id = col_double(),
book = col_character(),
book_num = col_double(),
chapter = col_character(),
chapter_num = col_double(),
character = col_character(),
full_text = col_character(),
character_words = col_character(),
writer = col_character(),
director = col_character(),
imdb_rating = col_double()
)
)
avatar %>%
glimpse()
## Rows: 13,385
## Columns: 11
## $ id <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1…
## $ book <chr> "Water", "Water", "Water", "Water", "Water", "Water"…
## $ book_num <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ chapter <chr> "The Boy in the Iceberg", "The Boy in the Iceberg", …
## $ chapter_num <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ character <chr> "Katara", "Scene Description", "Sokka", "Scene Descr…
## $ full_text <chr> "Water. Earth. Fire. Air. My grandmother used to tel…
## $ character_words <chr> "Water. Earth. Fire. Air. My grandmother used to tel…
## $ writer <chr> "Michael Dante DiMartino, Bryan Konietzko, Aaron Eh…
## $ director <chr> "Dave Filoni", "Dave Filoni", "Dave Filoni", "Dave F…
## $ imdb_rating <dbl> 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.1, 8.…
Tidy & Transform
avatar_ratings <-
avatar %>%
group_by(book, chapter_num) %>%
summarise(imdb_rating = median(imdb_rating), .groups = "drop_last") %>%
rowid_to_column() %>%
mutate(
book = ordered(book, levels = c("Water", "Earth", "Fire")),
best_worst = case_when(
rowid %in%
(slice_max(., order_by = imdb_rating) %>%
pluck("rowid")) ~ "best",
rowid %in%
(slice_min(., order_by = imdb_rating) %>%
pluck("rowid")) ~ "worst",
TRUE ~ "mid"
),
chapter_num = paste0("Chapter: ", as.character(chapter_num))
)
Visualise
theme_avatar()
5
avatar_ratings %>%
filter(!is.na(imdb_rating)) %>%
ggplot(aes(x = book, y = imdb_rating)) +
geom_dotplot(aes(fill = book), binaxis = "y", stackdir = "center") +
geom_label_repel(
avatar_ratings %>% filter(best_worst == "best"),
mapping = aes(label = chapter_num, color = book),
hjust = 0
) +
geom_label_repel(
avatar_ratings %>% filter(best_worst == "worst"),
mapping = aes(label = chapter_num, color = book),
hjust = 0
) +
scale_fill_manual(values = c("cadetblue3", "navy", "indianred3", legends = FALSE)) +
scale_color_manual(values = c("cadetblue3", "navy", "indianred3", legends = FALSE)) +
labs(
title = 'Avatar: The last airbender',
subtitle = "What were the highest and lowest rated chapters in each book?",
caption = '#TidyTuesday | @mstkolf'
) +
theme_avatar(
title.font = "Slayer",
title.size = 23, subtitle.size = 11,
legend.position = "none", axis.title.size = 15
)
References
Nakagawara, Ryo. 2019. Tvthemes: TV Show Themes and Color Palettes for ’Ggplot2’ Graphics. https://CRAN.R-project.org/package=tvthemes.
Reproducibility
## ─ Session info ───────────────────────────────────────────────────────────────
## setting value
## version R version 4.0.0 (2020-04-24)
## os macOS Catalina 10.15.5
## system x86_64, darwin17.0
## ui X11
## language (EN)
## collate ja_JP.UTF-8
## ctype ja_JP.UTF-8
## tz Asia/Tokyo
## date 2020-08-22
##
## ─ Packages ───────────────────────────────────────────────────────────────────
## package * version date lib source
## assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0)
## backports 1.1.7 2020-05-13 [1] CRAN (R 4.0.0)
## blob 1.2.1 2020-01-20 [1] CRAN (R 4.0.0)
## blogdown 0.20 2020-06-23 [1] CRAN (R 4.0.2)
## bookdown 0.20 2020-06-23 [1] CRAN (R 4.0.2)
## broom 0.7.0 2020-07-09 [1] CRAN (R 4.0.2)
## cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.0.0)
## cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0)
## colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.0)
## crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0)
## curl 4.3 2019-12-02 [1] CRAN (R 4.0.0)
## DBI 1.1.0 2019-12-15 [1] CRAN (R 4.0.0)
## dbplyr 1.4.4 2020-05-27 [1] CRAN (R 4.0.0)
## digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0)
## dplyr * 1.0.0 2020-05-29 [1] CRAN (R 4.0.0)
## ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.0)
## evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0)
## extrafont 0.17 2014-12-08 [1] CRAN (R 4.0.2)
## extrafontdb 1.0 2012-06-11 [1] CRAN (R 4.0.2)
## fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0)
## farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.0)
## flair * 0.0.2 2020-04-23 [1] CRAN (R 4.0.2)
## forcats * 0.5.0 2020-03-01 [1] CRAN (R 4.0.0)
## fs 1.4.1 2020-04-04 [1] CRAN (R 4.0.0)
## generics 0.0.2 2018-11-29 [1] CRAN (R 4.0.0)
## ggplot2 * 3.3.2 2020-06-19 [1] CRAN (R 4.0.2)
## ggrepel * 0.8.2 2020-03-08 [1] CRAN (R 4.0.2)
## glue 1.4.1 2020-05-13 [1] CRAN (R 4.0.0)
## gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0)
## haven 2.3.0 2020-05-24 [1] CRAN (R 4.0.0)
## here 0.1 2017-05-28 [1] CRAN (R 4.0.2)
## hms 0.5.3 2020-01-08 [1] CRAN (R 4.0.0)
## htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.2)
## httr 1.4.1 2019-08-05 [1] CRAN (R 4.0.0)
## jsonlite 1.6.1 2020-02-02 [1] CRAN (R 4.0.0)
## knitr 1.28 2020-02-06 [1] CRAN (R 4.0.0)
## labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0)
## lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0)
## lubridate 1.7.8 2020-04-06 [1] CRAN (R 4.0.0)
## magick 2.4.0 2020-06-23 [1] CRAN (R 4.0.2)
## magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0)
## modelr 0.1.8 2020-05-19 [1] CRAN (R 4.0.0)
## munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0)
## pillar 1.4.4 2020-05-05 [1] CRAN (R 4.0.0)
## pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0)
## purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.0.0)
## R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.0)
## Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 4.0.0)
## readr * 1.3.1 2018-12-21 [1] CRAN (R 4.0.0)
## readxl 1.3.1 2019-03-13 [1] CRAN (R 4.0.0)
## reprex 0.3.0 2019-05-16 [1] CRAN (R 4.0.0)
## rlang 0.4.7 2020-07-09 [1] CRAN (R 4.0.2)
## rmarkdown 2.3 2020-06-18 [1] CRAN (R 4.0.2)
## rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.0)
## rstudioapi 0.11 2020-02-07 [1] CRAN (R 4.0.0)
## Rttf2pt1 1.3.8 2020-01-10 [1] CRAN (R 4.0.2)
## rvest 0.3.5 2019-11-08 [1] CRAN (R 4.0.0)
## scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.0)
## sessioninfo * 1.1.1 2018-11-05 [1] CRAN (R 4.0.2)
## stringi 1.4.6 2020-02-17 [1] CRAN (R 4.0.0)
## stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.0.0)
## tibble * 3.0.3 2020-07-10 [1] CRAN (R 4.0.2)
## tidyr * 1.1.0 2020-05-20 [1] CRAN (R 4.0.0)
## tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.0)
## tidyverse * 1.3.0 2019-11-21 [1] CRAN (R 4.0.0)
## tvthemes * 1.1.0 2019-10-31 [1] CRAN (R 4.0.2)
## utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.0)
## vctrs 0.3.1 2020-06-05 [1] CRAN (R 4.0.0)
## withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.0)
## xfun 0.14 2020-05-20 [1] CRAN (R 4.0.0)
## xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.0)
## yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0)
##
## [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library