GOTTA CATCH ’EM ALL, POKEMON

Pokemon is a Japanese manga, anime, and video game. It was created in the 90’s and is one of the hightest grossing media franchises in the world, selling over 95 billion. The premise of the game is to ‘catch them all.’ By all meaning pocket monsters, or Pokemon. Catching every pokemon to play against other players and/or gym leaders to become the Pokemon master.

Majority of all the variables in this dataset are used in this project to show a comparison and contrast relationaip. We have about half of the variable quantitative which are expressing a Pokemon’s stats, a legendary variable which is binary and catergorical, and which generation did the pokemon originate which is a discrete variable.

This dataset was downloaded from Kaggle, but collected from a combination of Bulbapedia, pokemondb, and pokemon.com. The variables are based off the games. It displays raw attributes of when Pokemon are in battle, the HP, Defense, Attack, Special Attack and Defense, and Speed.

Load Data

 setwd("C:/Users/earlb/OneDrive/Documents/Data Science 110")
pokemon <- read.csv("pokemon.csv")

Load necessary libraries

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.1      ✔ purrr   1.0.1 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.5.0 
## ✔ readr   2.1.3      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(plotly)
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout

Select Columns being used

pokemon1 <- pokemon %>%
  select(Legendary, Type.1, Attack, Defense)

Explore Data

head(pokemon1)
##   Legendary Type.1 Attack Defense
## 1     FALSE  Grass     49      49
## 2     FALSE  Grass     62      63
## 3     FALSE  Grass     82      83
## 4     FALSE  Grass    100     123
## 5     FALSE   Fire     52      43
## 6     FALSE   Fire     64      58

Create Custom Color Palate

my_colors <- c("Fire" = "#FF6600", "Water" = "#0099FF", "Electric" = "#FFCC00", "Grass" = "#66CC00","Ice" = "#66CCFF", "Fighting" = "#FF0033", "Poison" = "#9933CC", "Ground" = "#996600","Flying" = "#6699FF", "Psychic" = "#FF3399", "Bug" = "#33CC33", "Rock" = "#CC9900",
"Ghost" = "#6600CC", "Dragon" = "#663300", "Dark" = "#333333", "Steel" = "#666699","Fairy" = "#FF99FF")

The above visualization shows the Legendary Pokemon’s types

Trying To Prove Correlation Between Attack and Defense

ggplot(pokemon, aes(x = Attack, y = Defense, color = Type.1)) +
  geom_point() +
  theme_bw() +
  scale_color_manual(values = my_colors) +
    geom_smooth(method = "lm", se = FALSE, size = 1, color = "pink") +
  ggtitle("Correlation between Defense and Attack by Type") +
  ylab("Pokemon Defense") +
  xlab("Attack Damage")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## `geom_smooth()` using formula = 'y ~ x'

The geom point graph above shows the correlation between attack damage and Pokemon defense by type. In the games types of pokemon play a big part in if the attack move is more effective or not.

ggplot(pokemon, aes(x = Attack, y = Defense, fill = Type.1)) +
  geom_area(color = "black", linewidth = 0.5) + 
   ggtitle("Correlation between Defense and Attack by Type") +
  ylab("Pokemon Defense") +
  xlab("Attack Damage")

# Interactive version of plot using plotly

The geom area visualization above shows whic type has the best attack and defense. From what we can see is psychic has some of the high attacks and ug has great defense, but this is not entirely true in the games.

pokeplot <- ggplot(pokemon, aes(x = Attack, y = Defense, color = Type.1)) + geom_point() +
  theme_bw() +
  scale_color_manual(values = my_colors) +
    geom_smooth(method = "lm", se = FALSE, size = 1, color = "pink") +
  ggtitle("Correlation between Defense and Attack") +
  ylab("Pokemon Defense") +
  xlab("Attack Damage")
playpoke <- ggplotly(pokeplot)
## `geom_smooth()` using formula = 'y ~ x'
print(playpoke)

Attack Vs Defense for Ghosts and Fairy pokemon

FairyGhost <- pokemon %>%
  filter(Type.1 %in% c("Fairy", "Ghost"))

The graph below shows the comparison of the pokemon types, Fairy versus Ghost. Pokemon have stats, attack, Defense, Speed, etc. These stats play a big part in determining how great of a pokemon you have caught. We can see the attack damage vs defense for the types in this visualization.

ggplot(FairyGhost, aes(y = Attack, x = Defense, color = Type.1)) +
  geom_point() +
  geom_line() +
  scale_color_manual(values = c("#FF99FF", "#6600cc")) + ggtitle("Ghosts VS Fairy Attack and Defense") +
  ylab("Pokemon Defense") +
  xlab("Attack Damage")

# Legendary Pokkemon vs Non Legendary Scatterplot

pokemon$Name <-as.factor(pokemon$Name)
pokemon$Legendary <-as.factor(pokemon$Legendary)
p2 <- pokemon %>%
  ggplot(aes(x = Name, y = Legendary), position = "dodge") +
  geom_jitter()
p2 +
  ggtitle("Legendary Pokemon Vs. Non Legendary") +
  xlab("Name of Pokemon")

This visualization shines a light on how rare having a legendary pokemon is. Out of 800 pokemon, FALSE, you can see there are only about 10-20 Legendary Pokemon.

pokemon$Legendary <-as.factor(pokemon$Legendary)
pokemon$Generation <-as.factor(pokemon$Generation)
p3 <- pokemon %>%
  ggplot(aes(x = Generation, fill = Legendary))+
  geom_bar()+
coord_flip() +
  ggtitle("Legendary Pokemon by Generation") 
p3

The bar chart avove shows ouf of each genration the amount of legendary pokemon in quantity for rach gen.

Attack Vs Defense for Legendary Pokemon

legendary <- pokemon %>%
  filter(Legendary %in% c("True"))
ggplot(legendary, aes(y = Attack, x = Defense, color = Type.1)) +
  geom_point() +
   scale_color_manual(values = my_colors) 

# Interactive Plot for Legendary Defense vs Attack

pokeplay2 <- ggplot(legendary, aes(y = Attack, x = Defense, color = Name)) +
  geom_point()

We’ve seen the amount of legendary pokemon in each genration, now with the below chunk let us compare which legendary has the strongest attack.

playpoke2 <- ggplotly(pokeplay2)
print(playpoke2)

Heat Map Showing Pokemon Stats

pokemon <- pokemon[order(pokemon$Total),] 
row.names(pokemon) <- pokemon$Name 
pokemon <- pokemon[, 5:9] 
pokemon_matrix <- data.matrix(pokemon) 
pokemon_heatmap <- heatmap(pokemon_matrix) 

The heatmap focuses on the stats of all the legendary okemon out of 6 generations. With this heatmap the quantitative variables, hp, Attack, Defense, Special Attack, Special Defense, Speed are observed in this heatmap.

Essay:

This project was one that Stina and I really enjoyed. We both are Pokemon fans and was enticed by the dataset and the visualizations that resulted from the given functions taught in class. I had faced issues with certain functions such as the mutate and filter. As stated above, the graphs that focuses on the Legendary Pokemon, I wanted to show who’s stronger, which legendary has the better stats, and the amount of legendary out of all the generations present in this dataset. We both knew Mewtwo, one of the original legendary pokemon, was going to show as one of the top contenders. This can be shown in chunk 139. I do wish this dataset was re-done with the updated generations and also had a variable for shiny pokemon.