Using IMDb’s data on top 100 Summer Movies to display their average viewer’s ratings
#TidyTuesday
{ggimage}
Author
Aditya Dahiya
Published
July 31, 2024
The dataset for this analysis is derived from the Internet Movie Database (IMDb) and focuses on movies with “summer” in their titles. The data includes a comprehensive list of these films, along with details such as their unique identifiers, titles, release years, runtimes, genres, and IMDb ratings. The information has been made available through the #TidyTuesday project, a weekly data project in the R community, encouraging data exploration and visualization. The specific datasets used in this analysis are summer_movies and summer_movie_genres, containing records of various movies and their associated genres.
How I made this graphic?
Loading libraries & data
Code
# Data Import and Wrangling Toolslibrary(tidyverse) # All things tidy# Final plot toolslibrary(scales) # Nice Scales for ggplot2library(fontawesome) # Icons display in ggplot2library(ggtext) # Markdown text support for ggplot2library(showtext) # Display fonts in ggplot2library(colorspace) # Lighten and Darken colourslibrary(seecolor) # To print and view colourslibrary(patchwork) # Combining plots# Getting the datasummer_movie_genres <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2024/2024-07-30/summer_movie_genres.csv')summer_movies <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2024/2024-07-30/summer_movies.csv')
# Colours to use as background and bordersmypal <- paletteer::paletteer_d("ggthemes::Summer")seecolor::print_color(mypal)bg_col <- mypal[6] |>lighten(0.9)seecolor::print_color(bg_col)text_col <- mypal[5] |>darken(0.7)seecolor::print_color(text_col)text_hil <- mypal[5] |>darken(0.4)seecolor::print_color(text_hil)##### Getting movie posters for the top movies ########## Get a custom google search engine and API key# Tutorial: https://developers.google.com/custom-search/v1/overview# google_api_key <- "LOAD YOUR GOOGLE API KEY HERE"# my_cx <- "GET YOUR CUSTOM SEARCH ENGINE ID HERE"# Load necessary packageslibrary(httr)library(magick)# Define function to download and save movie posterdownload_movie_poster <-function(movie_name, num_row) { api_key <- google_api_key cx <- my_cx# Build the API request URL url <-paste0("https://www.googleapis.com/customsearch/v1?q=", URLencode(paste0(movie_name, " movie poster")), "&cx=", cx, "&searchType=image&key=", api_key)# Make the request response <-GET(url) result <-content(response, "parsed")# Get the URL of the first image result image_url <- result$items[[1]]$link im <- magick::image_read(image_url)# Crop the image into a circle # (Credits: https://github.com/doehm/cropcircles) ic <- cropcircles::crop_circle( im, border_colour = text_col,border_size =0.2 ) ic2 <-image_read(ic) |>image_resize("x200")# set background as whiteimage_write(image = ic2,path = here::here("data_vizs", "temp_summer", paste0("temp_image_", num_row,".png")),format ="png" )}for (i in1:43) { num_row_i <- plotdf$id[i] movie_name_i <- plotdf$primary_title[i]download_movie_poster(movie_name_i, num_row_i)}
Visualization Parameters
Code
# Font for titlesfont_add_google("Corinthia",family ="title_font") # Font for the captionfont_add_google("Satisfy",family ="caption_font") # Font for plot textfont_add_google("Saira Extra Condensed",family ="body_font") showtext_auto()# Colours to use as background and bordersmypal <- paletteer::paletteer_d("ggthemes::Summer")seecolor::print_color(mypal)bg_col <- mypal[6] |>lighten(0.9)seecolor::print_color(bg_col)text_col <- mypal[5] |>darken(0.7)seecolor::print_color(text_col)text_hil <- mypal[5] |>darken(0.4)seecolor::print_color(text_hil)bts <-80# Caption stuff for the plotsysfonts::font_add(family ="Font Awesome 6 Brands",regular = here::here("docs", "Font Awesome 6 Brands-Regular-400.otf"))github <-""github_username <-"aditya-dahiya"xtwitter <-""xtwitter_username <-"@adityadahiyaias"social_caption_1 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{github};</span> <span style='color: {text_hil}'>{github_username} </span>")social_caption_2 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{xtwitter};</span> <span style='color: {text_hil}'>{xtwitter_username}</span>")plot_title <-"Summer Movies: \nTop 50"plot_subtitle <-"Names of Movies with\nYear of release &\nAverage IMDb\nRating in\nbrackets"str_view(plot_subtitle)plot_caption <-paste0("**Data:** _#TidyTuesday_ & IMDb", " | **Code:** ", social_caption_1, " | **Graphics:** ", social_caption_2 )rm(github, github_username, xtwitter, xtwitter_username, social_caption_1, social_caption_2)