Pokemon is a combination of ‘Pocket’ and ‘Monster’. So they’re all pretty small right? Not quite.
scale_format <- scales::
pokemon %>%
+
+
+
Maybe we need to work on this graph a little. Let’s make it log scaled on both axis. I’ll put myself in for reference too.
pokemon %>%
+
+
+
+
+
+
So after a log transform of the scales we have a (roughly) linear relationship. This is what we would expect in real world data. Nothing with a physical existence can have a 0 or negative measure for these features. Therefore, thinking of this in terms of average can be misleading. It will always be ‘long tailed’. It might be a stretch to refer to them all as Pocket Monsters though.
There’s also clearly a relationship between both height and weight. Let’s try and capture this in a single feature.
The body mass index is a simple metric to link height and weight. Let’s create it for our Pokemon.
{
weight/(height^2)
}
pokemon %>%
-> pokemon
pokemon %>%
+
+
Well, that’s something of a surprise. Looking at the scatter plots from earlier, there is something in the data set that is very small, but also extremely heavy. Let’s try and work out what that is.
pokemon %>%
%>%
%>%
%>%
name | height | weight | BMI | genus |
---|---|---|---|---|
Cosmoem | 0.1 | 999.9 | 99990.0000 | Protostar Pokémon |
Minior | 0.3 | 40.0 | 444.4444 | Meteor Pokémon |
Aron | 0.4 | 60.0 | 375.0000 | Iron Armor Pokémon |
Durant | 0.3 | 33.0 | 366.6667 | Iron Ant Pokémon |
Clamperl | 0.4 | 52.5 | 328.1250 | Bivalve Pokémon |
Torkoal | 0.5 | 80.4 | 321.6000 | Coal Pokémon |
Cacnea | 0.4 | 51.3 | 320.6250 | Cactus Pokémon |
Munchlax | 0.6 | 105.0 | 291.6667 | Big Eater Pokémon |
Sandygast | 0.5 | 70.0 | 280.0000 | Sand Heap Pokémon |
Beldum | 0.6 | 95.2 | 264.4444 | Iron Ball Pokémon |
There’s no accounting for cosmological battle entities. I’m going to claim that the Protostar Pokemon is a little out of scope for this and filter it out. Let’s have a look at what we’re left with.
Dave_BMI <-
pokemon %>%
%>%
+
+
+
So most Pokemon are actually a little bigger than me, and a few of them are a lot bigger! We’ve also realised that some of them might just be very different to me, like stars, made entirely of metal or rock, or maybe even giant dragons? Just like in the earlier article, I’m going to pivot the data so we get a comparison for dual type Pokemon on both their types.
pokemon %>%
%>%
%>%
%>%
+
+
+
+
So it looks like I’m not quite as hefty as Pokemon that are rock, steel, ice, ground, fighting, dark or dragon. That makes sense. I’m also a bit more corporeal than fairy or ghost type. Pokemon has some really big bugs though!
We’ve learned quite a few R programming things today. The most obvious were some ggplot
chart tools:
geom_vline()
and geom_hline()
make 1 dimensional lines at specific pointsgeom_histogram()
and geom_density()
show the distribution of a single value across mutiple observationsfacet_wrap()
can make grouped charts, which are often known as small multiplesscale_x_log10()
and scale_y_log10
is an easy way to plot a log axisscales
package is also useful for formatting the axis labelsDid you also notice the first thing we did with the scales
package? In R you can assign a function to a reference. This means that we don’t need to repeat ourselves if we want to set it up with the same arguments multiple times, like with formatting axis with large numbers.
In the tidyverse
world we also used the optional arguments in pivot_longer()
to select 2 columns to pivot on, and to drop rows we create that have NA
when the Pokemon only has 1 type.
Most importantly though, we created our own function, and it was easy! The BMI
function we created we used to make a single value, Dave_BMI
, but also to make the whole BMI
column for each Pokemon in the data set! That’s pretty cool.
From 2 known features, weight
and height
we made one single new measurement BMI
. This an example of something that will come up more in later posts about machine learning which is called ‘feature engineering’.
The next article will be going into how the Pokedex package is actually made, both in trying to design a ‘tidy’ data set, but also how to make a package in R!
P.S. I know that Pocket Monster
is related to the pokeballs they fit in, but that’s a less fun title.