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

Hi there.

This page is about creating a Pokémon (Gen 6+) Types Table In R. The Fairy type is introduced in Gen 6 (XY) which is included in the plot. The reference I am using is http://pokemondb.net/type.

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

Making A Pokémon Types Matrix Plot (Gen 1) In R

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

A Pokémon Types Table (Gen 6+)

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:

Creating A Pokémon Types Table In R

We start with creating the table of Pokémon Types with their damage multipliers. In this page we include all the type including Dark, Steel and the Fairy type.

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 18 for the 18 Pokémon types..

Since there are 18 Pokémon types, we would need 18 x 18 = 324 cases in our data table. These 324 cases translates to 324 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 324 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 324 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 still a very solid defensive choice as a lot of attacks do half damage to Steel types.
• Poison as an attacking type is not very great despite its advantage over the Fairy type.
• It is somewhat difficult to pick out the best attacking types. Candidates include Ground, Fire, Ice and Rock types.
• The Fairy type is okay for attacking. Its defense is decent as Dark, Fighting and Bug attacks are not very effective versus Fairy types. Dragon attacks have no effect on Fairy types. Only Steel and Poison moves are super effective versus Fairy.
• The Fire type is a good defensive type as well.