VOOZH about

URL: https://www.geeksforgeeks.org/r-language/introduction-to-the-pokemon-data-in-r/

⇱ Exploring Pokemon data in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Exploring Pokemon data in R

Last Updated : 7 May, 2025

Pokémon is more than a popular franchise. It is also a rich dataset full of patterns and insights. The data includes attributes such as HP, attack, defense, special stats, types, generation, and whether a Pokémon is legendary.

Dataset Overview

The dataset encompasses detailed attributes for each Pokémon, including:

  • Name: The Pokémon's name.
  • Type 1 & Type 2: Primary and secondary elemental types.
  • Total: Sum of all base stats.
  • HP: Hit Points, indicating health.
  • Attack & Defense: Physical attack and defense stats.
  • Special Attack & Special Defense: Stats for special moves.
  • Speed: Determines move order in battles.
  • Generation: The generation in which the Pokémon was introduced.
  • Legendary Status: Indicates if a Pokémon is legendary

Dataset Link: Pokemon dataset

Installing the Necessary Libraries

We will install and load the packages that we will use like ggplot2 , gridExtra and plotly using the install.packages() function and library() function.

Exploring the Dataset

We will now load our dataset and explore it contents , using various functions and statistical methods.

1. Loading the Data

We will read our dataset , which is the Pokemon.csv file using the function read.csv() function and display it first few rows.

Output:

👁 pokemon_head
Exploring Pokemon data in R

2. Using str() function

To display the pokemon_data data frame structure, the str function is used. The names and data types of each column, such as numerics, numbers, characters or factors, shall also be printed. This also gives insight into data organisation as a whole.

Output:

👁 str
Exploring Pokemon data in R

3. Using summary() function

Summarizing the dataset: The summary function shows a summary of the data, such as: statistics of numeric columns, mean, median, quartile, minimum, maximum and frequency counts.

Output:

👁 summary
Exploring Pokemon data in R

4. Explore specific columns

These lines of code gives the output of the names of the particular pokemon and their primary types.

Output:

👁 cols
Exploring Pokemon data in R

Various Visualizations of pokemon data

We will now plot various visualizations to explore the dataset further.

1. Histogram

This line of code shown the histogram of the attack column of the pokemon data.

Output:

👁 gh
Introduction to the Pokemon data in R

2. Bar Plot

This line of code shows the of bar plot , giving count for different types of pokemon (type.1).

Output:

👁 gh
Introduction to the Pokemon data in R

3. Scatter Plot

This code generates individual scatter plots for each pair of attributes (Attack vs Defence) with color-coding based on Pokémon types. This approach should be more manageable in terms of computation time. Adjustments can be made based on your specific needs and preferences.

Output:

👁 attackvsdefence
Attack vs Defence

4. Pie Chart

A quick glance at the ratio of legendary to unlegendary Pokémon can be found using a pie chart.

Output:

👁 Screenshot-(1464)
Pie chart visualization

5. Box Plot

We will create box plots for each pair of attributes (Sp..Def and Sp..Atk) for some selected pokemons.

Output:

👁 gh
Introduction to the Pokemon data in R

6. Column Plot

We will create a column plot to showcase speed vs defence for the different type1 pokemons.

Output:

👁 columnplot
Column Plot of Speed VS Defence

7. Step Plot

We randomly select 50 Pokémon from the dataset to simplify visualization. A step plot is then created using ggplot2 to show how Attack varies with HP, colored by the primary type (Type.1). The plot is displayed using grid.arrange(), allowing easy expansion for more plots later.

Output:

👁 Stepolt
Step Plot of HP vs Attack

In this article, we explored the rich dataset of Pokémon attributes using R, uncovering patterns and insights through various visualizations and analyses. From examining basic distributions to creating advanced plots, we demonstrated how this data can be used to understand relationships between features. This sets the stage for further exploration, such as clustering similar Pokémon or building predictive models for battle outcomes.

Comment

Explore