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.
setwd("C:/Users/earlb/OneDrive/Documents/Data Science 110")
pokemon <- read.csv("pokemon.csv")
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
pokemon1 <- pokemon %>%
select(Legendary, Type.1, Attack, Defense)
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
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
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)
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")
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.
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)
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.