Preprocessing

library(tidyverse)
library(echarts4r)

scoobydoo <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-07-13/scoobydoo.csv',
                             na = c("NA", " ", "NULL"))

scoobydoo %>%
  count(monster_real)
## # A tibble: 3 x 2
##   monster_real     n
##   <lgl>        <int>
## 1 FALSE          404
## 2 TRUE           112
## 3 NA              87
scoobydoo
## # A tibble: 603 x 75
##    index series_name  network season title   imdb engagement date_aired run_time
##    <dbl> <chr>        <chr>   <chr>  <chr>  <dbl>      <dbl> <date>        <dbl>
##  1     1 Scooby Doo,… CBS     1      What …   8.1        556 1969-09-13       21
##  2     2 Scooby Doo,… CBS     1      A Clu…   8.1        479 1969-09-20       22
##  3     3 Scooby Doo,… CBS     1      Hassl…   8          455 1969-09-27       21
##  4     4 Scooby Doo,… CBS     1      Mine …   7.8        426 1969-10-04       21
##  5     5 Scooby Doo,… CBS     1      Decoy…   7.5        391 1969-10-11       21
##  6     6 Scooby Doo,… CBS     1      What …   8.4        384 1969-10-18       21
##  7     7 Scooby Doo,… CBS     1      Never…   7.6        358 1969-10-25       21
##  8     8 Scooby Doo,… CBS     1      Foul …   8.2        358 1969-11-01       21
##  9     9 Scooby Doo,… CBS     1      The B…   8.1        371 1969-11-08       21
## 10    10 Scooby Doo,… CBS     1      Bedla…   8          346 1969-11-15       21
## # … with 593 more rows, and 66 more variables: format <chr>,
## #   monster_name <chr>, monster_gender <chr>, monster_type <chr>,
## #   monster_subtype <chr>, monster_species <chr>, monster_real <lgl>,
## #   monster_amount <dbl>, caught_fred <lgl>, caught_daphnie <lgl>,
## #   caught_velma <lgl>, caught_shaggy <lgl>, caught_scooby <lgl>,
## #   captured_fred <lgl>, captured_daphnie <lgl>, captured_velma <lgl>,
## #   captured_shaggy <lgl>, captured_scooby <lgl>, unmask_fred <lgl>,
## #   unmask_daphnie <lgl>, unmask_velma <lgl>, unmask_shaggy <lgl>,
## #   unmask_scooby <lgl>, snack_fred <lgl>, snack_daphnie <lgl>,
## #   snack_velma <lgl>, snack_shaggy <lgl>, snack_scooby <lgl>,
## #   unmask_other <lgl>, caught_other <lgl>, caught_not <lgl>,
## #   trap_work_first <lgl>, setting_terrain <chr>, setting_country_state <chr>,
## #   suspects_amount <dbl>, non_suspect <lgl>, arrested <lgl>,
## #   culprit_name <chr>, culprit_gender <chr>, culprit_amount <dbl>,
## #   motive <chr>, if_it_wasnt_for <chr>, and_that <chr>, door_gag <lgl>,
## #   number_of_snacks <chr>, split_up <dbl>, another_mystery <dbl>,
## #   set_a_trap <dbl>, jeepers <dbl>, jinkies <dbl>, my_glasses <dbl>,
## #   just_about_wrapped_up <dbl>, zoinks <dbl>, groovy <dbl>,
## #   scooby_doo_where_are_you <dbl>, rooby_rooby_roo <dbl>, batman <lgl>,
## #   scooby_dum <lgl>, scrappy_doo <lgl>, hex_girls <lgl>, blue_falcon <lgl>,
## #   fred_va <chr>, daphnie_va <chr>, velma_va <chr>, shaggy_va <chr>,
## #   scooby_va <chr>
skimr::skim(scoobydoo)
Data summary
Name scoobydoo
Number of rows 603
Number of columns 75
_______________________
Column type frequency:
character 23
Date 1
logical 33
numeric 18
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
series_name 0 1.00 4 42 0 29 0
network 0 1.00 3 20 0 11 0
season 0 1.00 1 9 0 7 0
title 0 1.00 4 76 0 602 0
format 0 1.00 5 21 0 5 0
monster_name 87 0.86 4 207 0 481 0
monster_gender 87 0.86 4 102 0 43 0
monster_type 87 0.86 5 166 0 132 0
monster_subtype 88 0.85 3 187 0 269 0
monster_species 87 0.86 3 134 0 194 0
setting_terrain 0 1.00 3 8 0 15 0
setting_country_state 0 1.00 4 16 0 79 0
culprit_name 163 0.73 2 169 0 433 0
culprit_gender 163 0.73 4 64 0 23 0
motive 67 0.89 4 16 0 27 0
if_it_wasnt_for 414 0.31 3 116 0 107 0
and_that 528 0.12 3 80 0 64 0
number_of_snacks 1 1.00 1 17 0 18 0
fred_va 219 0.64 9 18 0 5 0
daphnie_va 165 0.73 11 26 0 9 0
velma_va 218 0.64 9 19 0 12 0
shaggy_va 32 0.95 10 15 0 7 0
scooby_va 28 0.95 10 12 0 5 0

Variable type: Date

skim_variable n_missing complete_rate min max median n_unique
date_aired 0 1 1969-09-13 2021-02-25 1988-09-10 448

Variable type: logical

skim_variable n_missing complete_rate mean count
monster_real 87 0.86 0.22 FAL: 404, TRU: 112
caught_fred 219 0.64 0.34 FAL: 252, TRU: 132
caught_daphnie 165 0.73 0.07 FAL: 409, TRU: 29
caught_velma 218 0.64 0.11 FAL: 344, TRU: 41
caught_shaggy 32 0.95 0.13 FAL: 494, TRU: 77
caught_scooby 28 0.95 0.28 FAL: 415, TRU: 160
captured_fred 219 0.64 0.18 FAL: 313, TRU: 71
captured_daphnie 165 0.73 0.21 FAL: 347, TRU: 91
captured_velma 218 0.64 0.19 FAL: 311, TRU: 74
captured_shaggy 32 0.95 0.15 FAL: 486, TRU: 85
captured_scooby 28 0.95 0.14 FAL: 492, TRU: 83
unmask_fred 219 0.64 0.27 FAL: 282, TRU: 102
unmask_daphnie 165 0.73 0.08 FAL: 401, TRU: 37
unmask_velma 218 0.64 0.24 FAL: 291, TRU: 94
unmask_shaggy 32 0.95 0.02 FAL: 558, TRU: 13
unmask_scooby 28 0.95 0.04 FAL: 552, TRU: 23
snack_fred 219 0.64 0.05 FAL: 366, TRU: 18
snack_daphnie 165 0.73 0.11 FAL: 389, TRU: 49
snack_velma 218 0.64 0.08 FAL: 356, TRU: 29
snack_shaggy 31 0.95 0.08 FAL: 529, TRU: 43
snack_scooby 27 0.96 0.02 FAL: 564, TRU: 12
unmask_other 0 1.00 0.06 FAL: 568, TRU: 35
caught_other 0 1.00 0.14 FAL: 519, TRU: 84
caught_not 0 1.00 0.05 FAL: 572, TRU: 31
trap_work_first 354 0.41 0.50 TRU: 125, FAL: 124
non_suspect 160 0.73 0.10 FAL: 397, TRU: 46
arrested 155 0.74 0.85 TRU: 381, FAL: 67
door_gag 0 1.00 0.10 FAL: 544, TRU: 59
batman 0 1.00 0.01 FAL: 599, TRU: 4
scooby_dum 0 1.00 0.03 FAL: 586, TRU: 17
scrappy_doo 0 1.00 0.27 FAL: 438, TRU: 165
hex_girls 0 1.00 0.01 FAL: 597, TRU: 6
blue_falcon 0 1.00 0.05 FAL: 570, TRU: 33

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
index 0 1.00 302.00 174.22 1.0 151.5 302.0 452.50 603.0 ▇▇▇▇▇
imdb 15 0.98 7.28 0.73 4.2 6.9 7.3 7.70 9.6 ▁▁▇▆▁
engagement 15 0.98 580.33 4807.92 7.0 27.0 54.5 128.25 100951.0 ▇▁▁▁▁
run_time 0 1.00 23.52 17.21 4.0 12.0 22.0 23.00 94.0 ▇▃▁▁▁
monster_amount 0 1.00 1.75 2.29 0.0 1.0 1.0 2.00 19.0 ▇▁▁▁▁
suspects_amount 0 1.00 2.85 2.62 0.0 1.0 3.0 4.00 20.0 ▇▂▁▁▁
culprit_amount 0 1.00 1.04 1.07 0.0 0.0 1.0 1.00 11.0 ▇▁▁▁▁
split_up 219 0.64 0.34 0.55 0.0 0.0 0.0 1.00 2.0 ▇▁▃▁▁
another_mystery 219 0.64 0.18 0.41 0.0 0.0 0.0 0.00 3.0 ▇▂▁▁▁
set_a_trap 219 0.64 0.12 0.34 0.0 0.0 0.0 0.00 2.0 ▇▁▁▁▁
jeepers 165 0.73 0.56 1.30 0.0 0.0 0.0 1.00 10.0 ▇▁▁▁▁
jinkies 218 0.64 1.31 1.92 0.0 0.0 1.0 2.00 13.0 ▇▁▁▁▁
my_glasses 218 0.64 0.12 0.34 0.0 0.0 0.0 0.00 2.0 ▇▁▁▁▁
just_about_wrapped_up 218 0.64 0.05 0.22 0.0 0.0 0.0 0.00 1.0 ▇▁▁▁▁
zoinks 32 0.95 2.15 2.73 0.0 0.0 1.0 3.00 26.0 ▇▁▁▁▁
groovy 32 0.95 0.06 0.62 0.0 0.0 0.0 0.00 14.0 ▇▁▁▁▁
scooby_doo_where_are_you 32 0.95 0.13 0.42 0.0 0.0 0.0 0.00 4.0 ▇▁▁▁▁
rooby_rooby_roo 28 0.95 0.72 0.79 0.0 0.0 1.0 1.00 7.0 ▇▁▁▁▁
scoobydoo %>%
  count(series_name, season)
## # A tibble: 47 x 3
##    series_name                     season        n
##    <chr>                           <chr>     <int>
##  1 A Pup Named Scooby-Doo          1            13
##  2 A Pup Named Scooby-Doo          2             8
##  3 A Pup Named Scooby-Doo          3             4
##  4 A Pup Named Scooby-Doo          4             5
##  5 Be Cool, Scooby-Doo!            1            26
##  6 Be Cool, Scooby-Doo!            2            27
##  7 Dynomutt, Dogwonder             Crossover     3
##  8 Hanna-Barbera Superstars 10     Special       3
##  9 Harvey Birdman, Attorney at Law Crossover     1
## 10 Johnny Bravo                    Crossover     1
## # … with 37 more rows
monster_cum <- scoobydoo %>%
  arrange(date_aired, index) %>%
  select(index, series_name, season, title, date_aired, starts_with("caught_")) %>%
  pivot_longer(cols = starts_with("caught_"), names_to = "character", values_to = "caught_monster") %>%
  #drop_na(caught_monster) %>%
  mutate(caught_monster = replace_na(caught_monster, FALSE)) %>%
  group_by(character) %>%
  mutate(monster_caught_cum = cumsum(caught_monster)) %>%
  ungroup() %>%
  mutate(character = character %>% str_remove("caught_") %>% str_to_title() %>% str_replace("Not", "Not Caught"))

Bars animation without labels

monster_cum %>%
  #filter(series_name == "Scooby Doo, Where Are You!") %>%
  group_by(date_aired) %>%
  e_charts(character, timeline = TRUE) %>%
  e_bar(monster_caught_cum, 
        itemStyle = list(color = "#e78b9a")) %>%
  e_timeline_opts(loop = FALSE, playInterval = 50, autoPlay = FALSE) %>%
  e_flip_coords() %>%
  e_title(text = "Caught monsters by Scooby Doo characters",
          subtext = "Воскресный СкRинкаст 18.07.2021: Scooby Doo data",
          sublink = "https://github.com/rfordatascience/tidytuesday/blob/master/data/2021/2021-07-13/readme.md")

Bars animation with labels

monster_cum %>%
  #filter(series_name == "Scooby Doo, Where Are You!") %>%
  group_by(date_aired) %>%
  e_charts(character, timeline = TRUE) %>%
  e_bar(monster_caught_cum, 
        itemStyle = list(color = "#e78b9a"),
        label = list(show = TRUE,
                     color = "#000000",
                     fontWeight = 'bold',
                     fontSize = 14,
                     position = "right",
                     #backgroundColor = "#e78b9a",
                     formatter = '{@[1]}: {@[0]}')) %>%
  e_timeline_opts(loop = FALSE, playInterval = 50, autoPlay = FALSE) %>%
  e_flip_coords() %>%
  e_title(text = "Caught monsters by Scooby Doo characters",
          subtext = "Воскресный СкRинкаст 18.07.2021: Scooby Doo data",
          sublink = "https://github.com/rfordatascience/tidytuesday/blob/master/data/2021/2021-07-13/readme.md")