Creating A Pokémon (Gen 2 – 5) Types Matrix Plot In R

Hi there. This is a follow up to my previous page on making a Pokémon (Gen 1) types Table In R.

This page is about creating a Pokémon (Gen 2 to 5) Types Table In R. The Dark and Steel types were introduced starting from Generation 2 in the Gold/Silver (Johto) series.  The Fairy type is introduced in Gen 6 (XY) and is not in this table. The reference I am using is http://pokemondb.net/type.


Table Of Contents


References

  • http://stackoverflow.com/questions/10232525/geom-tile-heatmap-with-different-high-fill-colours-based-on-factor
  • http://stackoverflow.com/questions/16074440/r-ggplot2-center-align-a-multi-line-title
  • http://docs.ggplot2.org/dev/vignettes/themes.html
  • http://docs.ggplot2.org/current/theme.html
  • https://scriptsandstatistics.wordpress.com/2017/03/30/how-to-plot-a-companion-planting-guide-using-ggplot2/
  • http://pokemondb.net/type

Related Pages To This Include:

Cartesian Products In R

Making A Rock, Paper, Scissors Table In R

Creating A Rock, Paper, Scissors, Lizard, Spock Matrix Plot In R

Creating A Pokémon (Gen 2 – 5) Types Matrix Plot In R

Creating A Pokémon (Gen 6+) Types Table In R


A Pokémon Types Table (Gen 2-5)

The geom_tile() function from R’s ggplot2 package allows for grid plots and tables.

In R you can make something as close to this:

Source: https://img.pokemondb.net/images/typechart-gen2345.png


Creating A Pokémon Types Table In R

We start with creating the table of Pokémon Types with their damage multipliers.

This first line of R code is for creating the Pokémon Types as a vector.

We check that this vector has a count of 17 for the 17 Pokémon types (No Fairy type until Gen. 6/XY).

Since there are 17 Pokémon types, we would need 17 x 17 = 289 cases in our data table. These 289 cases translates to 289 rows in our table. The table could be inputted manually but that would take too long. Instead, the use of Cartesian products from the mathematical field of Set Theory along with R’s expand.grid() function is applied. Please refer to the code and output below.

We can check the dimensions of this Cartesian product table of Pokémon types.

Instead of viewing the whole table (of 289 rows), the head() and tail() functions are used to view a sample of the table.

An empty third column for Attack Damage multiplier is added. (NA means missing value)

The column titles are currently Var1 and Var2 with an unnamed third column name. The colnames() function is used to assign new column names.


Filling In The Third Column

This is the part where there is quite a bit of work. Because a third empty column was added there are 289 missing values denoted by NA. Each row where there is an attack type and defense type has to be dealt with separately. (There is no for/while loop solution here.)

If there is attack type advantage then the damage does normal damage (x1). This is denoted by 1 in the third column.

An attack type advantage over the defending Pokémon type results in double the damage applied from the attacking move to the defending Pokémon. This is denoted by 2 in the third column.

If there is an attack type which is not favourable against the defending Pokémon type results in half damage (x1/2). The attacking move was not very effective.

There are cases where certain attack types have no effect on the defending Pokémon type. The damage multiplier her is just 0.

Here is the full code for filling in the third column (Attack Damage Multiplier):

This next piece of code involves having the values from the third column as factors. In addition, I check the structure of the table and use the head() and tail() functions.


Creating The Pokémon Types Matrix Plot In R

The table of Pokémon Types and damage multipliers is now ready for plotting purposes.

The ggplot2 package in R for data visualization is first loaded.

Here is the code and output for the Pokémon types matrix plot. In this plot, the defending Pokémon types are on the x-axis (horizontal) and the attacking move type is on the y-axis (side/vertical).

 


Using The Pokémon Types Matrix Plot

For this section, we will refer to the plot that was just shown.

Using this table is not too hard.

As an example, if the defending Pokémon type is a Rock type and the attacking move is a water type then the attack would double the normal damage as indicated by the green square.

Dual Typed Defending Pokémon Cases

There are dual-typed Pokémon tables out there but you could use the single type table twice. As an example, an Ice type move to a Grass and Water type would deal normal damage (x1) as we have the multipliers of 2 and 1/2.

Simple Table Observations

  • One could use these types of tables to study type matchups for Pokémon selections in certain video games and competitions.
  • The Steel Type is a very solid defensive choice as a lot of attacks do half damage to Steel types.
  • Poison as an attacking type from Gen 2 to Gen 5 is not very great.
  • It is somewhat difficult to pick out the best attacking types. Candidates include Ground, Fire, Fighting, Ice and Rock types.
  • The Psychic type has a new weakness with the introduction of the Dark type. In addition, Psychic moves do half damage to the new Steel type.
  • The introduction of the Dark and Steel Types have given an attacking boost to Fighting type moves and have weakened Normal type moves further due to Normal type moves doing half damage to Steel types.

Leave a Reply