A simple scatterplot for weight and heights of different pokemons, coloured by their precribed colour, and a trend-line using geom_smooth(). The outlier pokemons are shown as images using ggimage::geom_image() and labelled with geom_text(). The title is shown as an annotation of a raster using {magick} and {grid}
#TidyTuesday
{magick}
ggimage
Images
Author
Aditya Dahiya
Published
April 1, 2025
About the Data
This week’s dataset dives into the world of Pokémon, sourced from the {pokemon} R package, available on CRAN and GitHub. Curated by Frank Hull, this dataset offers a comprehensive look at 949 Pokémon, with 22 columns detailing attributes like name, ID, height, weight, stats, types, and more, presented in both English and Brazilian Portuguese.
Figure 1: A simple scatterplot for weight and heights of different pokemons, coloured by their precribed colour, and a trend-line using geom_smooth(). The outlier pokemons are shown as images using ggimage::geom_image() and labelled with geom_text(). The title is shown as an annotation of a raster using {magick} and {grid}
How I made this graphic?
Loading required libraries
Code
# Data Import and Wrangling Toolslibrary(tidyverse) # All things tidy# Final plot toolslibrary(scales) # Nice Scales for ggplot2library(fontawesome) # Icons display in ggplot2library(ggtext) # Markdown text support for ggplot2library(showtext) # Display fonts in ggplot2library(colorspace) # Lighten and Darken colourslibrary(magick) # Download images and edit themlibrary(ggimage) # Display images in ggplot2library(patchwork) # composing Plotspokemon_df <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-04-01/pokemon_df.csv')pokemon_logo_url <-"https://1000logos.net/wp-content/uploads/2017/05/Pokemon-logo.jpg"
Visualization Parameters
Code
# Font for titlesfont_add_google("Alegreya",family ="title_font") # Font for the captionfont_add_google("Saira Extra Condensed",family ="caption_font") # Font for plot textfont_add_google("Unkempt",family ="body_font") showtext_auto()mypal <-c("yellow", "blue", "grey30")# cols4all::c4a_gui()# A base Colourbg_col <-"white"seecolor::print_color(bg_col)# Colour for highlighted texttext_hil <- mypal[3]seecolor::print_color(text_hil)# Colour for the texttext_col <- mypal[3]seecolor::print_color(text_col)line_col <-"grey30"# Define Base Text Sizebts <-120# Caption stuff for the plotsysfonts::font_add(family ="Font Awesome 6 Brands",regular = here::here("docs", "Font Awesome 6 Brands-Regular-400.otf"))github <-""github_username <-"aditya-dahiya"xtwitter <-""xtwitter_username <-"@adityadahiyaias"social_caption_1 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{github};</span> <span style='color: {text_hil}'>{github_username} </span>")social_caption_2 <- glue::glue("<span style='font-family:\"Font Awesome 6 Brands\";'>{xtwitter};</span> <span style='color: {text_hil}'>{xtwitter_username}</span>")plot_caption <-paste0("**Data:** {pokemon} by William Amorim", " | **Code:** ", social_caption_1, " | **Graphics:** ", social_caption_2 )rm(github, github_username, xtwitter, xtwitter_username, social_caption_1, social_caption_2)# Add text to plot-------------------------------------------------plot_subtitle <-"A simple scatterplot comparing heights and weights of different Pokemons. Outiers are shown with images (using {ggimage}) and labelled with geom_text(). A trendline shows general pattern."
# Saving a thumbnaillibrary(magick)# Saving a thumbnail for the webpageimage_read(here::here("data_vizs", "tidy_pokemon.png")) |>image_resize(geometry ="x400") |>image_write( here::here("data_vizs", "thumbnails", "tidy_pokemon.png" ) )# Remove temporary images# List all files in data_vizs that start with "temp_pokemon_"temp_files <-list.files(path = here::here("data_vizs"),pattern ="^temp_pokemon_.*",full.names =TRUE)# Remove the files (if any exist)file.remove(temp_files)
Session Info
Code
# Data Import and Wrangling Toolslibrary(tidyverse) # All things tidy# Final plot toolslibrary(scales) # Nice Scales for ggplot2library(fontawesome) # Icons display in ggplot2library(ggtext) # Markdown text support for ggplot2library(showtext) # Display fonts in ggplot2library(colorspace) # Lighten and Darken colourslibrary(magick) # Download images and edit themlibrary(ggimage) # Display images in ggplot2library(patchwork) # composing Plotssessioninfo::session_info()$packages |>as_tibble() |>select(package, version = loadedversion, date, source) |>arrange(package) |> janitor::clean_names(case ="title" ) |> gt::gt() |> gt::opt_interactive(use_search =TRUE ) |> gtExtras::gt_theme_espn()
Table 1: R Packages and their versions used in the creation of this page and graphics