Pokemon

Author

Jo Hardin

Published

April 1, 2025

Code
library(tidyverse) # ggplot, lubridate, dplyr, stringr, readr...
library(praise)

The Data

This week we are exploring Pokemon! This dataset is sourced from {pokemon} (CRAN | github), an R package which provides Pokemon information in both English and Brazilian Portuguese.

This package provides a dataset of Pokemon information in both English and Brazilian Portuguese. The dataset contains 949 rows and 22 columns, including information such as the Pokemon’s name, ID, height, weight, stats, type, and more.

Thank you to Frank Hull for curating this week’s dataset.

Code
pokemon_df <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-04-01/pokemon_df.csv')

Using color

The Pokemon dataset came with Hex colors!! Such a cool and easy way to use the hex color values to color the points.

Code
pokemon_df |> 
  ggplot(aes(x = attack, y = defense, color = color_1)) + 
  geom_point() +
  scale_color_identity() + 
  facet_wrap(~type_1)

Scatterplot with Pokemon attack points on the x-axis and defense points on the y-axis. The scatterplots are faceted by type of Pokemon (including fighting, fire, electric, etc.).

Attack and defense values broken down by color and facet by type of Pokemon.

Radar plots

The goal here was to create a single spider line for each Pokemon, but to put a group of spider lines on a single polygon, faceted by type of Pokemon (e.g., fire, water, psychic, etc.). I couldn’t make it work. :(

We spent a lot of time on the spider plot, so today’s work doesn’t feel very satisfying. But on the flip side, I learned about scale_color_identity(), and I also learned some map() tricks (see below).

Code
library(ggradar)

set.seed(47)
pokemon_df |> 
  sample_n(10) |> 
  select(pokemon, weight, height, speed, attack, defense) |> 
  drop_na() |> 
  mutate(across(where(is.numeric), ~ (. - min(.)) / (max(.) - min(.))))  |> 
  #rownames_to_column("group") |> 
  rename(group = pokemon) |> 
  ggradar() + 
  facet_wrap(~`Group.1`)

Code
pokemon_df |> 
  sample_n(20) |> 
  select(group = type_1, weight, height, speed, attack, defense) |> 
  drop_na() |> 
  mutate(across(where(is.numeric), ~ (. - min(.)) / (max(.) - min(.)))) |> 
  (\(df) split(df, df$group))() |> 
  map(~{.x |> 
      select(-group) |> 
      ggradar()})
$bug


$dark


$fairy


$fire


$grass


$ground


$ice


$normal


$rock


$water

Code
praise()
[1] "You are hunky-dory!"