Code
library(tidyverse)
ice_movies <- read_delim(
"https://query.data.world/s/pmbfldxflx7ttdyfs23cx3abehcl5c",
delim = ";",
escape_double = FALSE,
trim_ws = TRUE,
locale = locale(encoding = "ISO-8859-1")
)The given R script uses the ggplot2 package to look at and show how movie theater attendance and ticket sales have changed over time. It works with data from the ice_movies dataset by collecting it, changing it, and showing it visually. There are two main analyses in the script. First, it looks at monthly trends in admissions by getting the weekend.start date, putting it in the right format, and then adding up all the data by month to get the total number of weekend admissions. ggplot2 is used to make a time-series visualization with a line plot with highlighted points and a smoothing curve that shows trends in the number of people who came to the event. Second, the script looks at the top 20 highest-grossing movies by sorting the dataset by movie titles and finding the movies’ highest total box office earnings. The best-performing movies are found, put in order from best to worst, and shown visually on a horizontal bar chart.
library(tidyverse)
ice_movies <- read_delim(
"https://query.data.world/s/pmbfldxflx7ttdyfs23cx3abehcl5c",
delim = ";",
escape_double = FALSE,
trim_ws = TRUE,
locale = locale(encoding = "ISO-8859-1")
)boxoffice_data <- ice_movies |>
group_by(film_title = film.title) |>
summarise(total_box = max(`total.box.o.to.date`, na.rm = TRUE)) |>
ungroup() |>
top_n(20, wt = total_box) |>
arrange(desc(total_box))
temporal <- ice_movies |>
mutate(
weekend_date = as.Date(weekend.start, format = "%Y-%m-%d")
) |>
mutate(
month = floor_date(weekend_date, "month")
) |>
group_by(month) |>
summarise(total_admissions = sum(adm.weekend, na.rm = TRUE)) |>
ungroup()
ggplot(temporal, aes(x = month, y = total_admissions)) +
geom_line(color = "green", linewidth = 1) +
geom_point(color = "yellow", size = 2) +
geom_smooth(method = "loess", formula = y ~ x, se = FALSE, color = "gray40") +
scale_x_date(date_breaks = "3 months", date_labels = "%b %Y") +
labs(
title = "Trends in Monthly Admissions",
subtitle = "A visualization of admission changes over time",
x = "Month",
y = "Admissions Count"
) +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 50, hjust = 1),
panel.grid.major = element_line(color = "gray80")
)ggplot(boxoffice_data, aes(x = fct_reorder(film_title, total_box), y = total_box)) +
geom_col(fill = "orange") +
coord_flip() +
scale_y_continuous(labels = function(x) format(x, big.mark = ",")) + # Replacing comma() with format()
labs(
title = "Top 20 Films by Total Box Office Earnings",
x = "Film Title",
y = "Total Box Office (USD)"
) +
theme_minimal()temporal <- ice_movies |>
mutate(
weekend_date = as.Date(weekend.start, format = "%Y-%m-%d")
) |>
mutate(
month = floor_date(weekend_date, "month")
) |>
group_by(month) |>
summarise(total_admissions = sum(adm.weekend, na.rm = TRUE)) |>
ungroup()
ggplot(temporal, aes(x = month, y = total_admissions)) +
geom_line(color = "green", linewidth = 1) +
geom_point(color = "yellow", size = 2) +
geom_smooth(method = "loess", formula = y ~ x, se = FALSE, color = "gray40") +
scale_x_date(date_breaks = "3 months", date_labels = "%b %Y") +
labs(
title = "Trends in Monthly Admissions",
subtitle = "A visualization of admission changes over time",
x = "Month",
y = "Admissions Count"
) +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 50, hjust = 1),
panel.grid.major = element_line(color = "gray80")
)Overall, the script does a good job of looking into important parts of the movie business by combining data manipulation and visualization techniques. The first graph shows how movie theater attendance changes over time, which could show seasonal patterns or changes across the whole industry. The second visualization shows the most commercially successful movies by comparing how much money they made at the box office. These studies look at both how engaged the audience was and how well the movie did financially. This makes them useful for industry experts, producers, and marketers who want to understand how the market works and make the most of future movie releases.