library(tidyverse)
library(jsonlite)
AE 13: Rectangling data from the PokéAPI
Packages
We will use the following packages in this application exercise.
- tidyverse: For data import, wrangling, and visualization.
- jsonlite: For importing JSON files
Gotta catch em’ all!
Pokémon (also known as Pocket Monsters) is a Japanese media franchise consisting of video games, animated series and films, a trading card game, and other related media.1 The PokéAPI contains detailed information about each Pokémon, including their name, type, and abilities. In this application exercise, we will use a set of JSON files containing API results from the PokéAPI to explore the Pokémon universe.
1 Source: Wikipedia
Importing the data
data/pokedex.json
and data/types.json
contain information about each Pokémon and the different types of Pokémon, respectively. We will use read_json()
to import these files.
<- read_json(path = "data/pokemon/pokedex.json")
pokemon <- read_json(path = "data/pokemon/types.json") types
Your turn: Use View()
to interactively explore each list object to identify their structure and the elements contained within each object.
Unnesting for analysis
For each of the exercises below, use an appropriate rectangling procedure to unnest_*()
one or more lists to extract the required elements for analysis.
How many Pokémon are there for each primary type?
Your turn: Use each Pokemon’s primary type to determine how many Pokémon there are for each type, then create a bar chart to visualize the distribution. The chart should label each Pokémon type in both English and Japanese.
# add code here
Which primary type of Pokémon are strongest based on total number of points?
Your turn: Use each Pokémon’s base stats to determine which primary type of Pokémon are strongest based on the total number of points. Create a boxplot to visualize the distribution of total points for each primary type.
# add code here
From what types of eggs to Pokemon hatch?
In Generation II, Pokémon introduced the concept of breeding, where Pokémon can produce offspring. In Generation III, Pokémon eggs were introduced, which can be hatched to produce a Pokémon.
Use each Pokémon’s egg group to determine from what types of eggs Pokémon hatch. Create a heatmap like the one below to visualize the distribution of egg groups for each primary type.
Consider using hoist()
to extract the main type and egg group from each Pokémon.
# add code here
Acknowledgments
- JSON data files obtained from
Purukitto/pokemon-data.json