Horror Movies

Author

Tony Galvan

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.3.6      ✔ purrr   0.3.5 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.4.1 
✔ readr   2.1.3      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(lubridate)

Attaching package: 'lubridate'

The following objects are masked from 'package:base':

    date, intersect, setdiff, union
library(gt)
library(gtExtras)

tt_caption <- "Source: The Movie Database   |  DataViz: Tony Galvan (@GDataScience1) #TidyTuesday"

image_url_prefix <- "https://www.themoviedb.org/t/p/w1280"

readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-11-01/horror_movies.csv') %>%
  select(-adult) %>%
  mutate(release_year = year(release_date),
         backdrop_path = paste0(image_url_prefix, backdrop_path),
         poster_path = paste0(image_url_prefix, poster_path)) %>%
  filter(vote_count >= 1000,
         runtime > 60) %>%
  top_n(5, wt = vote_average) %>%
  arrange(desc(vote_average)) %>%
  mutate(rank = row_number(),
         votes = vote_count,
         title = paste0(title, " (", release_year, ") - ", runtime, " minutes")) %>%
  select(rank, poster_path, backdrop_path, title, vote_average, revenue, votes, vote_count) %>%
  gt() %>%
  text_transform(
    locations = cells_body(columns = c(poster_path, backdrop_path)),
    fn = function(x){
      web_image(
        url = x,
        height = 100
      )
    }
  ) %>%
  tab_header(
    title = md("**Highest Rated Horror Movies**"),
    subtitle = "With at least 1000 votes"
  ) %>%
  tab_source_note(
    source_note = tt_caption
  ) %>%
  cols_label(rank = md("**Rank**"),
             poster_path = "",
             backdrop_path = "",
             title = md("**Title**"),
             vote_average = md("**Rating**"),
             revenue = md("**Revenue**<br>(in millions)"),
             votes = md("**Votes**"),
             vote_count = ""
  ) %>%
  gt_plt_bar(column = vote_count, width = 40, color = "red") %>%
  fmt_number(columns = votes, decimals = 0) %>%
  fmt_currency(columns = revenue, decimals = 1, scale = 0.000001, suffixing = TRUE) %>%
  cols_align(columns = c(rank, vote_average, revenue), align = "center") %>%
  tab_options(table.background.color = "gray25") %>%
  cols_width(revenue ~ px(140)) %>%
  opt_table_font(
    font = list(
      google_font(name = "Creepster"),
      default_fonts()
    )
  ) %>%
  tab_options(
    heading.title.font.size = 48
  ) %>%
  tab_style(
    style = cell_text(size = "xx-large"),
    locations = cells_body(
      columns = rank
    )
  )
Rows: 32540 Columns: 20
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (10): original_title, title, original_language, overview, tagline, post...
dbl   (8): id, popularity, vote_count, vote_average, budget, revenue, runtim...
lgl   (1): adult
date  (1): release_date

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Warning: The value for `scale_by` cannot be changed if `suffixing` is anything other
than `FALSE`.
• The value provided to `scale_by` will be ignored.
Highest Rated Horror Movies
With at least 1000 votes
Rank Title Rating Revenue
(in millions)
Votes
1 Psycho (1960) - 109 minutes 8.4 $50.0M 8,452
2 The Shining (1980) - 144 minutes 8.2 $44.8M 14,911
3 Alien (1979) - 117 minutes 8.1 $104.9M 12,083
4 The Thing (1982) - 109 minutes 8.0 $19.6M 5,566
5 The Black Phone (2022) - 103 minutes 7.9 $161.0M 2,736
Source: The Movie Database | DataViz: Tony Galvan (@GDataScience1) #TidyTuesday