library(readxl)
movies_data <- read_xlsx("Top-Movie-Per-Year-Individual.xlsx")
The interactive plots show “Adjusted Gross” twice when hovering over a data point. I could not figure out how to correct that.
# Load packages
library(ggplot2)
library(dplyr)
library(gapminder)
library(dplyr)
library(plotly)
movies_data$unfactored_mpaa <- movies_data$`MPAA rating`
movies_data$`MPAA rating` <- factor(movies_data$`MPAA rating`, levels = c("G", "PG", "PG-13", "R"))
movie_ggplot <-
ggplot(movies_data,
aes(x = Year, y = `Adjusted Gross`,
size = `Adjusted Gross`,
fill = `MPAA rating`,
text = paste("Movie:", `Number 1 Release`))) +
geom_point(alpha = 0.5, shape = 21, stroke = 0.5, color = 'black',
position = position_jitter(height = 0)) +
scale_y_continuous(labels = scales::dollar_format()) +
scale_size_continuous(range = c(1, 10),
labels = function(x) paste0(round(x / 1e9, 1), "B")) +
labs(title = "Adjusted Gross Revenue, Year, MPAA Rating of Top Movies (Domestic)",x = "Year", y = "Adjusted Gross (USD)") +
theme_minimal() +
guides(fill = guide_legend(override.aes = list(size = 5)))
movie_ggplot
(plotly cut off the rest of the title and didn’t know how to fix)
plotly_interactive <- ggplotly(movie_ggplot)
#plotly_interactive <- plotly::style(plotly_interactive, marker = list(line = list(width = 0.5)))
plotly_interactive
plotly_interactive2 <- ggplotly(movie_ggplot2, sizes = c(10, 30))
plotly_interactive2 <- plotly::style(plotly_interactive2, marker = list(line = list(width = 0.5)))
plotly_interactive2