I have three data sets saved as csv files.The data sets are sales for video games.The data is from back in 2016 3 years after the PlayStation 4 and the Xbox one had been released.The sales are given as millions of units sold in specific regions such as North America, Europe and Japan. One data set includes critic and user scores.
With this data set I hope to compare user and critic scores to the number of units a game sold in each region. I also plan to find the top sold games in both companies displaying the names. Finally I am going to compare the average units of games sold for Playstation and Xbox in each region.
For this report I import and download the tidyverse packages.I plan to use ggplot and dplyr to visualize and format my data frames.The tidyverse also has packages useful for reading the data and manipulating the character strings in the data frame.
knitr::opts_chunk$set(echo =TRUE)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 4.3.3
##
## Attaching package: 'gridExtra'
##
## The following object is masked from 'package:dplyr':
##
## combine
I will be pulling in 3 data files with comma separated values. Using the readr package we can load in the data and store it in a data frame. The read.csv() function has a parameter to set up the frame as long as we identify how the data is organized.
game_Sale <- read.csv("Video_Games_Sales.csv", sep = ",")
xbox_sale <- read.csv("PS4_GamesSales.csv", sep = ",")
PS4_sale <- read.csv("XboxOne_GameSales.csv", sep = ",")
Before trying to manipulate the data or trying to create visual models I will look at a summary of the data. The quick overview of the data allows for more effective data models. This prevents a trial and error approach when choosing how to represent the data as a graph. For example, choosing to use a bar graph, line,histogram, or even a pie chart. First we will look at the PS4 then Xbox and finally the overall sales.
summary(PS4_sale)
## Pos Game Year Genre
## Min. : 1 Length:613 Length:613 Length:613
## 1st Qu.:154 Class :character Class :character Class :character
## Median :307 Mode :character Mode :character Mode :character
## Mean :307
## 3rd Qu.:460
## Max. :613
## Publisher North.America Europe Japan
## Length:613 Min. :0.0000 Min. :0.0000 Min. :0.000000
## Class :character 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.000000
## Mode :character Median :0.0500 Median :0.0000 Median :0.000000
## Mean :0.2656 Mean :0.1324 Mean :0.000832
## 3rd Qu.:0.2400 3rd Qu.:0.1000 3rd Qu.:0.000000
## Max. :4.7000 Max. :3.2500 Max. :0.040000
## Rest.of.World Global
## Min. :0.00000 Min. :0.0000
## 1st Qu.:0.00000 1st Qu.:0.0000
## Median :0.01000 Median :0.0600
## Mean :0.03995 Mean :0.4389
## 3rd Qu.:0.03000 3rd Qu.:0.3800
## Max. :0.76000 Max. :8.7200
summary(xbox_sale)
## Game Year Genre Publisher
## Length:1034 Length:1034 Length:1034 Length:1034
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## North.America Europe Japan Rest.of.World
## Min. :0.0000 Min. :0.0000 Min. :0.00000 Min. :0.00000
## 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.00000 1st Qu.:0.00000
## Median :0.0200 Median :0.0000 Median :0.00000 Median :0.01000
## Mean :0.2046 Mean :0.2487 Mean :0.03364 Mean :0.08901
## 3rd Qu.:0.1200 3rd Qu.:0.1300 3rd Qu.:0.03000 3rd Qu.:0.05000
## Max. :6.1800 Max. :9.7100 Max. :2.17000 Max. :3.02000
## Global
## Min. : 0.0000
## 1st Qu.: 0.0000
## Median : 0.0600
## Mean : 0.5761
## 3rd Qu.: 0.3575
## Max. :19.3900
summary(game_Sale)
## Name Platform Year_of_Release Genre
## Length:16719 Length:16719 Length:16719 Length:16719
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## Publisher NA_Sales EU_Sales JP_Sales
## Length:16719 Min. : 0.0000 Min. : 0.000 Min. : 0.0000
## Class :character 1st Qu.: 0.0000 1st Qu.: 0.000 1st Qu.: 0.0000
## Mode :character Median : 0.0800 Median : 0.020 Median : 0.0000
## Mean : 0.2633 Mean : 0.145 Mean : 0.0776
## 3rd Qu.: 0.2400 3rd Qu.: 0.110 3rd Qu.: 0.0400
## Max. :41.3600 Max. :28.960 Max. :10.2200
##
## Other_Sales Global_Sales Critic_Score Critic_Count
## Min. : 0.00000 Min. : 0.0100 Min. :13.00 Min. : 3.00
## 1st Qu.: 0.00000 1st Qu.: 0.0600 1st Qu.:60.00 1st Qu.: 12.00
## Median : 0.01000 Median : 0.1700 Median :71.00 Median : 21.00
## Mean : 0.04733 Mean : 0.5335 Mean :68.97 Mean : 26.36
## 3rd Qu.: 0.03000 3rd Qu.: 0.4700 3rd Qu.:79.00 3rd Qu.: 36.00
## Max. :10.57000 Max. :82.5300 Max. :98.00 Max. :113.00
## NA's :8582 NA's :8582
## User_Score User_Count Developer Rating
## Min. :0.000 Min. : 4.0 Length:16719 Length:16719
## 1st Qu.:6.400 1st Qu.: 10.0 Class :character Class :character
## Median :7.500 Median : 24.0 Mode :character Mode :character
## Mean :7.125 Mean : 162.2
## 3rd Qu.:8.200 3rd Qu.: 81.0
## Max. :9.700 Max. :10665.0
## NA's :9129 NA's :9129
After checking the data summary we see that the data frame containing 2016 game sales in general has NA values. We also see in the Xbox and PS4 data frames we have 0 values affecting the minimum values. This is something to keep in mind if trying to create predicative values. Another thing to note is the years columns are character values and not numeric. If plotting the years I need to change the values to numeric rather then as characters.
g_Sale <- na.omit(as.numeric(game_Sale$Year_of_Release))
## Warning in na.omit(as.numeric(game_Sale$Year_of_Release)): NAs introduced by
## coercion
x_Sale <- na.omit(as.numeric(xbox_sale$Year))
## Warning in na.omit(as.numeric(xbox_sale$Year)): NAs introduced by coercion
p_Sale <- na.omit(as.numeric(PS4_sale$Year))
## Warning in na.omit(as.numeric(PS4_sale$Year)): NAs introduced by coercion
In an attempt to change the data type and clear the NA at the same time an error has occured. I have kept this in mind for the rest of the document but doesn’t seem to affect the work flow.
After viewing the data I conclude the sales columns in tables are the number of units sold in millions of each game. Keeping this in mind I am going to list the name of the games with the most sold copies from each region across all game companies. Then I am going make a scatter plot to see if there is a correlation between critic scores and units sold in each region. Finally I am going to create a bar graph that will compare the average units sold in each region between the Xbox one and the PS4.
The code below is used to create new tables with the data arranged from highest sales to lowest.A new table is created for each region of the world then globally.
nA_5<-arrange(game_Sale,desc(NA_Sales))
eU_5<-arrange(game_Sale,desc(EU_Sales))
jA_5<-arrange(game_Sale,desc(JP_Sales))
Global_5<-arrange(game_Sale,desc(Global_Sales))
cat("The 5 most sold games in North America are:\n")
## The 5 most sold games in North America are:
cat(nA_5$Name[1:5], sep = "\n")
## Wii Sports
## Super Mario Bros.
## Duck Hunt
## Tetris
## Mario Kart Wii
cat("The 5 most sold games in Europe are:\n")
## The 5 most sold games in Europe are:
cat(eU_5$Name[1:5], sep = "\n")
## Wii Sports
## Mario Kart Wii
## Nintendogs
## Wii Sports Resort
## Brain Age: Train Your Brain in Minutes a Day
cat("The 5 most sold games in Japan are:\n")
## The 5 most sold games in Japan are:
cat(jA_5$Name[1:5], sep = "\n")
## Pokemon Red/Pokemon Blue
## Pokemon Gold/Pokemon Silver
## Super Mario Bros.
## New Super Mario Bros.
## Pokemon Diamond/Pokemon Pearl
cat("The 5 most sold games Globally are:\n")
## The 5 most sold games Globally are:
cat(Global_5$Name[1:5], sep = "\n")
## Wii Sports
## Super Mario Bros.
## Mario Kart Wii
## Wii Sports Resort
## Pokemon Red/Pokemon Blue
#crit_plot<-
ggplot(na.omit(game_Sale),aes(x=Critic_Score,y = Global_Sales,
color=Genre))+ geom_point() + # Add points
labs(x = "Critic Ratings", y = "Units Sold ($millions)") +
ggtitle("Correlation of Critic Ratings and Sales")
This first scatter plot shows the density of the critic scores to global
sales. Essentially the correlation is low but there is still slight
correlation. The higher critic scores do display slightly higher
sales.
#user_plot<-
ggplot(na.omit(game_Sale),aes(x=User_Score,y = Global_Sales,
color=Genre))+geom_point() + # Add points
labs(x = "Consumer Ratings", y = "Units Sold ($millions)") +
ggtitle("Correlation between User Rating and Sales")
#cor.test(game_Sale$User_Score, game_Sale$Global_Sales)
#grid.arrange(crit_plot, user_plot, ncol = 2)#package to place two plots
#side by side