Skip to main content

AE 12: Rectangling data from the PokéAPI

Application exercise
Modified

October 14, 2026

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 single JSON file containing API results from the PokéAPI to explore the Pokémon universe.

Importing the data

data/pokedex.json contains information about each Pokémon. We will use read_json() to import this file.

pokemon <- read_json(path = "data/pokemon/pokedex.json")

Your turn: View the imported object to understand its structure using the Session > Variables pane in Positron.

Unnesting for analysis

For each of the exercises below, use an appropriate rectangling procedure to unnest_*() the list 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 (the first one listed in the data) 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.

TipChoose a rectangling approach

Examine the contents of each list object to determine how the relevant variables are structured so you can plan your approach.

There are (at least) three ways you could approach this problem.

  1. Use unnest_wider() twice to extract the primary type from the pokemon list and generate a frequency count.
  2. Use unnest_wider() and hoist() to extract the primary type from the pokemon list and generate a frequency count.
  3. Use unnest_wider() and unnest_longer() to extract the primary type from the pokemon list and generate a frequency count.

Pick one and have at it!

# 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.

TipChoose a rectangling approach

To calculate the sum total of points for each Pokémon’s base stats, there are two approaches you might consider. In either approach you first need to get each Pokémon’s variables into separate columns and extract the primary type.

  1. Use unnest_wider() to extract the base stats, then calculate the sum of the base stats.
  2. Use unnest_longer() to extract the base stats, then calculate the sum of the base stats.
# add code here

Acknowledgments

Footnotes

  1. Source: Wikipedia↩︎