# A tibble: 3 × 2
status n
<chr> <int>
1 legendary 71
2 mythical 23
3 regular 931
Six numbers per Pokémon, where the new axes come from, and what ‘variance explained’ means
2026-11-30
Important
⚠️ Set down one habit
For nine weeks, “did it work?” meant “is p small?”
Today you judge your result by whether you can explain what the axes mean.
prcomp()Tools today:
tidyverseplotly — you installed it for the mapping weeksData: 🔴 all 1,025 Pokémon, six battle stats each
Tip
No new packages. prcomp() is built into R.
Note
📖 The six stats
hp — hit pointsattack — physical attackdefense — physical defencesp_attack — special attacksp_defense — special defencespeed — speedGame-design numbers, but they behave exactly like six measurements off an animal.
We will cover:
status is one column built from two TRUE/FALSE ones
TRUE ~ catches everything left overstatus — PCA never sees itNote
🧠 Mythical?
A second “rare and special” group in the game — Mew is mythical, Mewtwo is legendary.
hp, sp_attack, sp_defense are missingImportant
✅ Hold on to this
Rotating to find the angle that shows the most spread is exactly what PCA does.
It just does it in six dimensions, where we cannot rotate anything by hand.
Warning
⚠️ The real problem
“Which Pokémon are similar to each other?” is a question about all six numbers at the same time.
Looking at them two at a time cannot answer it.
[1] 1025 6
Note
🧠 Why a separate table
statuspokemon
We will cover:
hp attack defense sp_attack sp_defense speed
hp 1.00 0.48 0.30 0.36 0.37 0.18
attack 0.48 1.00 0.47 0.28 0.23 0.35
defense 0.30 0.47 1.00 0.21 0.50 0.01
sp_attack 0.36 0.28 0.21 1.00 0.49 0.42
sp_defense 0.37 0.23 0.50 0.49 1.00 0.21
speed 0.18 0.35 0.01 0.42 0.21 1.00
1.00 — each column against itself. Ignore itdefense & sp_defense: 0.50sp_attack & sp_defense: 0.49hp & attack: 0.48attack & defense: 0.47speed & defense: 0.01Important
✅ This is what makes PCA work
Correlation is redundancy.
PCA’s whole job is to squeeze the redundancy out.
If all six were completely unrelated, there would be nothing to squeeze — six axes in, six equally useless axes out.
scale. = TRUE, that table is literally the inputWarning
⚠️ The one real caution
Do not put in the same thing twice.
A “total stats” column next to the six stats it was added up from would count everything twice.
Here the biggest correlation is 0.50 — nowhere near a duplicate.

attack vs defense, r = 0.47
\[\text{PC1} = a_1\,\text{hp} + a_2\,\text{attack} + \ldots\]
Note
🧠 Two words you need
Loading — how much an original stat contributes to a PC. What the axis is made of — the \(a\)’s.
Score — where one Pokémon sits along that PC. Its new measurement.
Loadings describe the axis. Scores describe the Pokémon.
Tip
🎯 That is PCA
PCA finds the angle that casts the most informative shadow of the 6-D cloud — the one where the points stay as spread out as possible.
Then it reports what that shadow is made of.
# A tibble: 1 × 6
hp attack defense sp_attack sp_defense speed
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 26.6 29.8 29.3 29.7 26.6 28.7
Warning
⚠️ A worked disaster
Measure animals in grams and kilometres.
Unscaled, PC1 would be entirely mass — it would only tell you which unit you typed.
scale. = TRUE turns every column into standard deviations from its own meanWe will cover: prcomp(), summary(), variance explained, and the scree plot.
Note
🧠 That is the entire analysis
center = TRUE — subtract each column’s meanscale. = TRUE — divide by each column’s standard deviationpoke_pcaImportance of components:
PC1 PC2 PC3 PC4 PC5
Standard deviation 1.6265 1.0509 0.9391 0.8192 0.65141
Proportion of Variance 0.4409 0.1841 0.1470 0.1119 0.07072
Cumulative Proportion 0.4409 0.6250 0.7719 0.8838 0.95451
PC6
Standard deviation 0.52243
Proportion of Variance 0.04549
Cumulative Proportion 1.00000
summary()Standard deviation)Proportion of Variance — share of the total spread each PC holds
Cumulative Proportion — the running total
Important
✅ The headline
Two invented axes carry 62.5% of everything in six columns.
So one flat scatterplot of PC1 against PC2 shows you nearly two-thirds of the whole dataset.
Warning
⚠️ Not 44% of the Pokémon
And not 44% accuracy.
It is 44% of the total variation — of the differences between them.
# A tibble: 6 × 2
PC percent
<chr> <dbl>
1 PC1 44.1
2 PC2 18.4
3 PC3 14.7
4 PC4 11.2
5 PC5 7.1
6 PC6 4.5
Note
🧠 Where that came from
poke_pca$sdev = each PC’s standard deviationsummary() printed — but in a data frame, so we can plot themWarning
⚠️ There is no rule
People argue about the elbow constantly. Rough guides:
That last one is the most useful.
We will cover:
PC1 PC2
hp 0.42 0.10
attack 0.43 0.07
defense 0.39 0.58
sp_attack 0.43 -0.36
sp_defense 0.44 0.16
speed 0.31 -0.70
Important
✅ Look at the PC1 column: every number is positive (0.31 to 0.44)
# A tibble: 3 × 6
name hp attack speed PC1 PC2
<chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 bulbasaur 45 49 45 -1.53 -0.0589
2 ivysaur 60 62 60 -0.286 -0.152
3 venusaur 80 82 80 1.43 -0.244
Note
🧠 poke_pca$x holds the scores
mutate() can glue them straight onImportant
✅ Why this matters beyond Pokémon
This is the check you run on every PCA.
You cannot test whether an axis is “real”. But you can look at what sits at each end and ask whether it lines up with something you already know.
If it does not, be very careful.
# A tibble: 3 × 3
status n mean_PC1
<chr> <int> <dbl>
1 legendary 71 2.38
2 mythical 23 2.25
3 regular 931 -0.24
Note
🧠 Reading it
text = name is not a real ggplot aesthetic — ggplotly() picks it up for the hoverTip
🎯 Close dots = similar Pokémon
Two dots near each other have similar stat profiles overall — the all-six-at-once question we could not answer with 15 scatterplots.
And this one plot holds 62.5% of the six columns.
We have:
We do not have:
Both are next class.
Tip
🎯 A hint about PC2
In PC2, defense is +0.58 and speed is −0.70.
A big positive and a big negative on the same axis means a trade-off, not a total.
Which trade-off? Next class.
filter() right after you read the fileNote
📂 How it works
YOUR CODE, copy the matching section from today’s scriptscale. = TRUENote
✅ Next
Open the activity and type it in. Next class: what PC2 means, and the biplot. 🔴