# Load required packages
library(tidyverse)
library(plotly)
# Import video game sales dataset
games <- read.csv("Video_Games_Sales_as_at_22_Dec_2016.csv")
# Select variables needed and remove missing values
games_clean <- games %>%
select(
Name,
Genre,
Platform,
Year_of_Release,
Critic_Score,
Global_Sales
) %>%
drop_na()
# Create customized hover text for interactive display
games_clean <- games_clean %>%
mutate(
hover_text = paste(
"<b>", Name, "</b>",
"<br>Genre:", Genre,
"<br>Platform:", Platform,
"<br>Release Year:", Year_of_Release,
"<br>Critic Score:", Critic_Score,
"<br>Global Sales:", Global_Sales, "Million"
)
)
# Create interactive scatter plot
plot_ly(
data = games_clean,
x = ~Critic_Score,
y = ~Global_Sales,
color = ~Genre,
text = ~hover_text,
hoverinfo = "text",
type = "scatter",
mode = "markers"
) %>%
layout(
title = "Relationship Between Critic Scores and Global Video Game Sales",
xaxis = list(title = "Critic Score"),
yaxis = list(title = "Global Sales (Millions)")
)
This interactive scatter plot displays the relationship between critic scores and global video game sales. Each point representing an individual game, with the x-axis showing the critic score and the y-axis showing global sales in millions. The points are color coded by genre, allowing viewers to compare categories such as Action, Sports, Shooter, etc. The plot helps identify trends between critical acclaim and commercial success while also revealing any outliers that may have achieved high sales while receiving lower review scores or vise versa. The customized hover text provides additional information including the game title, genre, platform, release year, critic score, and global sales. A slight challenge encountered during the creation of this visualization was handling missing values in the dataset. This issue was resolved by removing incomplete observations using the drop_na() function, ensuring that all displayed points contained complete information.
# Problem 2
# Create animated scatter plot
fig <- games_clean %>%
plot_ly(
x = ~Critic_Score,
y = ~Global_Sales,
color = ~Genre,
text = ~hover_text,
hoverinfo = "text"
) %>%
add_markers(
frame = ~Year_of_Release
) %>%
# Customize and enlarge the frame label
animation_slider(
currentvalue = list(
prefix = "Year: ",
font = list(
size = 28,
color = "black"
)
)
) %>%
# Slow down animation speed
animation_opts(
frame = 3000,
transition = 500
) %>%
layout(
title = "Video Game Sales and Critic Scores by Release Year",
xaxis = list(title = "Critic Score"),
yaxis = list(title = "Global Sales (Millions)")
)
fig
This animated scatter plot illustrates the relationship between critic scores and global video game sales over time. The x-axis represents critic scores, while the y-axis represents global sales in millions of units sold. Each point represents a video game and is color coded according to its genre. The animation progresses through release years, allowing viewers to observe how games are distributed across different years and how sales patterns change over time.