library(ggplot2)
library(trelliscopejs)
library(tidyverse)
data <- read.csv("vgSales.csv")
# Group by Genre and create the new variable
games <- data %>%
  group_by(Genre) %>%
  mutate(percent_NA_Sales = mean(NA_Sales/Global_Sales))

# Add the description
games$percent_NA_Sales <- cog(games$percent_NA_Sales, desc = "Percentge of Global Sales that are from NA")
ggplot(games, aes(NA_Sales, EU_Sales)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  xlim(c(0,20)) +
  ylim(c(0,15)) +
  facet_trelliscope(~ Genre,
                    name = "Video Game Sales (NA vs. EU)",
                    desc = "By Genre",
                    nrow = 2, ncol = 2,
                    scales = "same",
                    path = ".",
                    self_contained = TRUE)
# The data set above contains many rows of various video games along with their respective sales. The sales are split into several subtypes, including overall global sales, North American sales, European sales, Japanese sales, and Other sales. In these graphs, I am plotting the relationship between North American and European sales, to investigate which genres are most similar in sales between the continents. I decided to facet on genre because there are a decent number of them (12 different genres), allowing for the trelliscope function to show more than just a few graphs. Also, I was curious to see if certain genres are more popular in Europe vs. North America, such as Fighting games.

# The challenges I had in making the graph were first to find multiple numerical values to graph as a scatterplot, as this data only contains years and sales data, with the rest as categorical data. I decided to compare EU vs. NA with the expectation that most of the graphs would result in high correlations (as one continent's sales increase, so should the other's). However, I figured that individual points would be more important to notice which genres have some disparity, rather than looking at all points as a whole.

# A cognostic measure that I created was percentage of global sales that are from NA. I thought this would be beneficial to see which genres are more popular in North America vs. the rest of the world. It appears that Adventure games have the lowest percentage of sales in NA (26.9%) and Platform games (Mario) have the highest percentage (56.5%). It was surprising to see that Mario games have the highest percentage of sales, as that is widely known to be a brand created in Japan. While I know that Japan has a smaller population than NA and would expect to be a lower sales total, it was still interesting to notice that fact.

Or go to web: https://rpubs.com/Coltyn_Lusk/1478891