library(tidyverse)
library(lubridate)
library(ggrepel)
ice_movies <- read_delim ("https://query.data.world/s/pmbfldxflx7ttdyfs23cx3abehcl5c", ";", locale = locale(encoding = "ISO-8859-2",
asciify = TRUE))
ice_movies_2 <- ice_movies %>% select(blog.date, film.title, adm.to.date, total.box.o.to.date) %>% mutate(month = month(blog.date, label = TRUE), year = year(blog.date)) %>% group_by(month, year) %>% drop_na() %>% summarize(avg.adm.to.date = mean(adm.to.date))
top_movies <- ice_movies %>% mutate(month = month(blog.date, label = TRUE), year = year(blog.date)) %>% group_by(month, year, film.title) %>% drop_na() %>% summarize(top.box.office = mean(total.box.o.to.date)) %>% select(film.title, top.box.office, month, year) %>% distinct() %>% ungroup() %>% slice_max(order_by = top.box.office, n = 20, with_ties = FALSE)
top_movies_year <- top_movies %>% group_by(film.title) %>% filter(top.box.office == max(top.box.office))
top_movies_year_2 <- inner_join(ice_movies_2, top_movies_year, by= c("year" = "year", "month" = "month")) %>% filter(year < 2021 & year >= 2018) %>% select(film.title, top.box.office, month, year, avg.adm.to.date)
ice_movies_2 %>% filter(year < 2021 & year >= 2018) %>%
ggplot(aes(x = month, y = avg.adm.to.date, group = factor(year), fill = factor(year), color = factor(year))) + geom_line(size = 1) +
scale_color_brewer(palette = "Set2") +
scale_fill_brewer(palette = "Set2") +
geom_point(data = top_movies_year_2, mapping = aes(month, avg.adm.to.date), size = 3) +
geom_label_repel(data = top_movies_year_2, mapping = aes(label = film.title), force_pull = 0, color = "white", ylim=c(1800, 4600), xlim=c(1,12), segment.linetype = 5, min.segment.length = 0, segment.color = "grey", size=2.8, fontface = "bold") + guides(fill = guide_legend(override.aes = aes(fill = NA, label = ""))) +
ylim(0, 15000) +
ylab("Average movie admissions") +
xlab("Month") +
labs(title = "Average movie admission numbers in Iceland by month for 2018, 2019, and 2020", subtitle = "with top box office films by month", caption = "Data Source: Movie attendance in Iceland") +
theme_minimal() + theme(legend.position = "bottom")
