library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
library(readr)
library(knitr)
library(ggplot2)
Here we import and read the CSV file from Github. Then we make it a data frame for easy cleaning.
#import
assignment6b <- "https://raw.githubusercontent.com/lgreski/pokemonData/master/Pokemon.csv"
#read
pokemon<-read.csv(assignment6b)
#dataframe
data_frame(pokemon)
## Warning: `data_frame()` is deprecated, use `tibble()`.
## This warning is displayed once per session.
## # A tibble: 894 x 1
## pokemon$Number $Name $Type1 $Type2 $Total $HP $Attack $Defense
## <int> <fct> <fct> <fct> <int> <int> <int> <int>
## 1 1 Bulb~ Grass Poison 318 45 49 49
## 2 2 Ivys~ Grass Poison 405 60 62 63
## 3 3 Venu~ Grass Poison 525 80 82 83
## 4 3 Venu~ Grass Poison 625 80 100 123
## 5 4 Char~ Fire <NA> 309 39 52 43
## 6 5 Char~ Fire <NA> 405 58 64 58
## 7 6 Char~ Fire Flying 534 78 84 78
## 8 6 Char~ Fire Dragon 634 78 130 111
## 9 6 Char~ Fire Flying 634 78 104 78
## 10 7 Squi~ Water <NA> 314 44 48 65
## # ... with 884 more rows, and 5 more variables: $SpecialAtk <int>,
## # $SpecialDef <int>, $Speed <int>, $Generation <int>, $Legendary <lgl>
Becoming a Pokemon Master is easy. Defeating other Pokemon Masters is hard. Making a pokemone battle team using the ‘Job Strategy’ means giving each of your Pokemon a specific task to help win the battle. We will be finding the best Pokemon for each Job for the ultimate fighting team.
First we’re going to calculate each Pokemon’s Job rating. Then we’re going to pick out the top 10 Pokemon from each Job category.
#Sweepers are used to take out as many opponents as possible. They need high HP and either a high Attack or high Special Attack.
pokemon <- mutate(pokemon, Sweeper1 = HP+Attack, Sweeper2 = HP+SpecialAtk)
#Top Sweepers
topsweepers <- pokemon %>%
gather(Sweeper, SPoints, 14:15) %>%
arrange(desc(SPoints)) %>%
top_n(10) %>%
select(Name, SPoints)
## Selecting by SPoints
topsweepers
## Name SPoints
## 1 Blissey 330
## 2 Guzzlord 324
## 3 Guzzlord 320
## 4 Slaking 310
## 5 MewtwoMega Mewtwo Y 300
## 6 MewtwoMega Mewtwo X 296
## 7 KyuremBlack Kyurem 295
## 8 KyuremWhite Kyurem 295
## 9 RayquazaMega Rayquaza 285
## 10 Chansey 285
## 11 RayquazaMega Rayquaza 285
#Tanks are used to withstand as much damage as possible. They need high HP and both high Defense and Special Defense.
pokemon <- mutate(pokemon, Tank = HP+Defense+SpecialDef)
#Top Tanks
toptanks <- pokemon %>%
arrange(desc(Tank)) %>%
top_n(10) %>%
select(Name, Tank)
## Selecting by Tank
toptanks
## Name Tank
## 1 Shuckle 480
## 2 SteelixMega Steelix 400
## 3 Blissey 400
## 4 Lugia 390
## 5 GiratinaAltered Forme 390
## 6 AggronMega Aggron 380
## 7 Regirock 380
## 8 Regice 380
## 9 Registeel 380
## 10 Stakataka 373
#Drainers are Sweepers who are Grass, Bug, or Poison type.
pokemon <- mutate(pokemon, Drainer1 = HP+Attack, Drainer2 = HP+SpecialAtk)
#Top Drainers
topdrainers <- pokemon %>%
gather(Drainer, DPoints, 17:18) %>%
arrange(desc(DPoints)) %>%
filter(Type1 == c("Grass","Bug","Poison")|Type2 == c("Grass","Bug","Poison")) %>%
top_n(10) %>%
select(Name, DPoints)
## Selecting by DPoints
topdrainers
## Name DPoints
## 1 Kartana 240
## 2 GengarMega Gengar 230
## 3 Vikavolt 222
## 4 PinsirMega Pinsir 220
## 5 Gogoat 220
## 6 SceptileMega Sceptile 215
## 7 Pheromosa 208
## 8 Escavalier 205
## 9 VenusaurMega Venusaur 202
## 10 Yanmega 202
#Stallers are Tanks who are Rock, Ground, or Steel type.
pokemon <- mutate(pokemon, Staller = HP+Defense+SpecialDef)
#Top Stallers
topstallers <- pokemon %>%
arrange(desc(Staller)) %>%
filter(Type1 == c("Rock", "Ground", "Steel")|Type2 == c("Rock", "Ground", "Steel")) %>%
top_n(10) %>%
select(Name, Staller)
## Selecting by Staller
topstallers
## Name Staller
## 1 Shuckle 480
## 2 SteelixMega Steelix 400
## 3 AggronMega Aggron 380
## 4 Regirock 380
## 5 Registeel 380
## 6 Stakataka 373
## 7 Probopass 355
## 8 Steelix 340
## 9 MetagrossMega Metagross 340
## 10 Groudon 330
#Closers are used to get a fast hit for the finishing blow. They need high Attack and high Speed.
pokemon <- mutate(pokemon, Closer = Attack+Speed)
#Top Closers
topclosers <- pokemon %>%
arrange(desc(Closer)) %>%
top_n(10) %>%
select(Name, Closer)
## Selecting by Closer
topclosers
## Name Closer
## 1 DeoxysAttack Forme 330
## 2 MewtwoMega Mewtwo X 320
## 3 DeoxysNormal Forme 300
## 4 NecrozmaUltra 296
## 5 BeedrillMega Beedrill 295
## 6 RayquazaMega Rayquaza 295
## 7 MewtwoMega Mewtwo Y 290
## 8 Kartana 290
## 9 Pheromosa 288
## 10 AerodactylMega Aerodactyl 285
Now we’re going to make a data frame of each of the top battle Pokemon. Lets see which Type of Pokemon appear most frequently.
#The A Team
ATeam <- bind_cols(distinct(topsweepers), toptanks, topdrainers, topstallers, topclosers)
#We filtered out the Types of each Pokemon earlier. Let's add them back in. First we put all the Names into one column.
help_me_pick<-gather(ATeam, "Column", "Name", c(1,3,5,7,9))
#Next we add the original columns from the dataset Pokemon to our ATeam.
toppokemon<-left_join(help_me_pick, pokemon, by='Name')
## Warning: Column `Name` joining character vector and factor, coercing into
## character vector
#Next we put all of the Primary and Secondary Types into one column.
toppokemon<-gather(toppokemon, "Column1", "Type", c(9,10))
#Now we can count the frequency each Type appears in the Top Pokemon data. Some Pokemon only have a Primary type so we exclude empty Secondary types.
besttype<-toppokemon %>%
group_by(Type) %>%
filter(Type != "") %>%
count(Type)
#Now we can plot which Type has the most Top Pokemon.
spread(besttype, Type, n)
## # A tibble: 1 x 15
## Bug Dark Dragon Electric Fighting Flying Ghost Grass Ground Ice
## <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
## 1 9 2 9 1 4 6 2 5 4 3
## # ... with 5 more variables: Normal <int>, Poison <int>, Psychic <int>,
## # Rock <int>, Steel <int>
ggplot(data.frame(besttype), aes(x=Type, y=n)) +
geom_bar(stat="identity")
It looks like if you’re trying to build the ultimate fighting team, you should travel to places with high numbers of Steel type Pokemon.
For beginners, this can be a lot to take in. Some people want to just start playing the game and have fun. But with so many generations of Pokemon, which will give you the overall best chance of success? Lets find the generation with the highest average rank of Pokemon.
#Pick 1 generation
pokemon %>%
group_by(Generation) %>%
summarise(mean(Total))
## # A tibble: 7 x 2
## Generation `mean(Total)`
## <int> <dbl>
## 1 1 427.
## 2 2 418.
## 3 3 436.
## 4 4 459.
## 5 5 435.
## 6 6 436.
## 7 7 461.
And there you have it. If you’re just going to pick one generation to start playing with, start with Gen 7.