Assignment Description

Create a visualization from this week’s provided data (‘Movie attendance in Iceland’ courtesy of data.world) that shows the relationship of any variable with one of the date columns. The single chart visualization must utilize ggplot2, show the relationship between the variables chosen, correctly handle and represent date elements, include a descriptive title using ggtitle and contain no warnings, messages or typos in the report.

Data

Load the data set. Prep the data to visualize total gross weekend admissions (in millions) by month per year for years 2017 - 2020 (since 2021 only has one month of data).

# Load required packages
library (knitr)
library (tidyverse)
library (lubridate)

# Load the *'Movie attendance in Iceland'* data set from *data.world* (use *ISO-8859-2 locale encoding with asciify set to TRUE* to replace foreign non-ASCII characters with their ASCII equivalents)
rawData <- read_delim ("https://query.data.world/s/pmbfldxflx7ttdyfs23cx3abehcl5c", ";", locale = locale (encoding = "ISO-8859-2", asciify = TRUE))

# Add month and year columns for the weekend end dates to the existing data set
rawData <- rawData %>%
  mutate (weekend.end.month = month (weekend.end, label = TRUE), weekend.end.year = year (weekend.end))

# Pare down the data set to include the minimum for depicting total weekend gross admissions (in millions) sorted by month per year (drop any resulting records with no data) for months 2017 - 2020
preppedData <- rawData %>%
  arrange (weekend.end) %>%
  transmute (gross.box.o.weekend, weekend.end.year, weekend.end.month) %>%
  drop_na () %>%
  group_by (weekend.end.year, weekend.end.month) %>%
  summarize (weekend.end.gross.in.millions = sum (gross.box.o.weekend) / 1000000) %>%
  filter (weekend.end.year < 2021)

Charts

Plot the total gross box office weekend admissions (in millions) by month and year.

# Plot total weekend admissions by month per year
preppedData %>%
  ggplot (aes (x = weekend.end.month, y = weekend.end.gross.in.millions, group = 1)) +
  geom_line () +
  facet_wrap (~ weekend.end.year) +
  xlab ("Month") +
  ylab ("Admissions (in millions)") +
  ggtitle ("Iceland Gross Box Office Weekend Admissions by Month\nMay 2017 - Dec 2020") +
  theme_minimal () +
  theme (plot.title = element_text (hjust = 0.5), axis.text.x = element_text (angle = 90, vjust = 0.5))