12  Actividad: Explorando con datos de Pokémon

Instructor: Zuriel Ceja

Notas personales de Zuriel. Espero que les funcione 💜

Nota

Presentación completa en Google slides.

12.1 1. Descarga de los datos de Pokémon

Este análisis exploratorio examina el dataset de Pokémon de Tidy Tuesday. Verificaremos la calidad de los datos, realizaremos limpieza necesaria y crearemos visualizaciones para entender mejor las características de los Pokémon.

Código
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Código
pokemon <- read.csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-04-01/pokemon_df.csv")
head(pokemon, 10) %>% 
  DT::datatable(rownames = FALSE)

12.2 2. Verificación Inicial de la Información

Código
# Dimensiones
cat("Dimensiones del dataset:", nrow(pokemon), "filas x", ncol(pokemon), "columnas\n\n")
Dimensiones del dataset: 949 filas x 22 columnas
Código
# Tipos de datos
str(pokemon)
'data.frame':   949 obs. of  22 variables:
 $ id             : int  1 2 3 4 5 6 7 8 9 10 ...
 $ pokemon        : chr  "bulbasaur" "ivysaur" "venusaur" "charmander" ...
 $ species_id     : int  1 2 3 4 5 6 7 8 9 10 ...
 $ height         : num  0.7 1 2 0.6 1.1 1.7 0.5 1 1.6 0.3 ...
 $ weight         : num  6.9 13 100 8.5 19 90.5 9 22.5 85.5 2.9 ...
 $ base_experience: int  64 142 236 62 142 240 63 142 239 39 ...
 $ type_1         : chr  "grass" "grass" "grass" "fire" ...
 $ type_2         : chr  "poison" "poison" "poison" NA ...
 $ hp             : int  45 60 80 39 58 78 44 59 79 45 ...
 $ attack         : int  49 62 82 52 64 84 48 63 83 30 ...
 $ defense        : int  49 63 83 43 58 78 65 80 100 35 ...
 $ special_attack : int  65 80 100 60 80 109 50 65 85 20 ...
 $ special_defense: int  65 80 100 50 65 85 64 80 105 20 ...
 $ speed          : int  45 60 80 65 80 100 43 58 78 45 ...
 $ color_1        : chr  "#78C850" "#78C850" "#78C850" "#F08030" ...
 $ color_2        : chr  "#A040A0" "#A040A0" "#A040A0" NA ...
 $ color_f        : chr  "#81A763" "#81A763" "#81A763" NA ...
 $ egg_group_1    : chr  "monster" "monster" "monster" "monster" ...
 $ egg_group_2    : chr  "plant" "plant" "plant" "dragon" ...
 $ url_icon       : chr  "//archives.bulbagarden.net/media/upload/7/7b/001MS6.png" "//archives.bulbagarden.net/media/upload/a/a0/002MS6.png" "//archives.bulbagarden.net/media/upload/0/07/003MS6.png" "//archives.bulbagarden.net/media/upload/7/7d/004MS6.png" ...
 $ generation_id  : int  1 1 1 1 1 1 1 1 1 1 ...
 $ url_image      : chr  "https://raw.githubusercontent.com/HybridShivam/Pokemon/master/assets/images/001.png" "https://raw.githubusercontent.com/HybridShivam/Pokemon/master/assets/images/002.png" "https://raw.githubusercontent.com/HybridShivam/Pokemon/master/assets/images/003.png" "https://raw.githubusercontent.com/HybridShivam/Pokemon/master/assets/images/004.png" ...
Código
# Resumen rápido
summary(pokemon)
       id             pokemon      species_id        height      
 Min.   :    1   Length   :949   Min.   :  1.0   Min.   : 0.100  
 1st Qu.:  238   N.unique :949   1st Qu.:191.0   1st Qu.: 0.500  
 Median :  475   N.blank  :  0   Median :395.0   Median : 1.000  
 Mean   : 1900   Min.nchar:  3   Mean   :400.1   Mean   : 1.228  
 3rd Qu.:  712   Max.nchar: 23   3rd Qu.:615.0   3rd Qu.: 1.500  
 Max.   :10147                   Max.   :802.0   Max.   :14.500  
                                                                 
     weight       base_experience       type_1          type_2   
 Min.   :  0.10   Min.   : 36.0   Length   :949   Length   :949  
 1st Qu.:  8.50   1st Qu.: 68.0   N.unique : 18   N.unique : 18  
 Median : 28.80   Median :157.0   N.blank  :  0   N.blank  :  0  
 Mean   : 66.21   Mean   :150.5   Min.nchar:  3   Min.nchar:  3  
 3rd Qu.: 66.60   3rd Qu.:184.0   Max.nchar:  8   Max.nchar:  8  
 Max.   :999.90   Max.   :608.0                   NAs      :439  
                                                                 
       hp             attack          defense       special_attack  
 Min.   :  1.00   Min.   :  5.00   Min.   :  5.00   Min.   : 10.00  
 1st Qu.: 50.00   1st Qu.: 55.00   1st Qu.: 50.00   1st Qu.: 50.00  
 Median : 65.00   Median : 75.00   Median : 70.00   Median : 65.00  
 Mean   : 68.95   Mean   : 79.47   Mean   : 74.07   Mean   : 72.81  
 3rd Qu.: 80.00   3rd Qu.:100.00   3rd Qu.: 90.00   3rd Qu.: 95.00  
 Max.   :255.00   Max.   :190.00   Max.   :230.00   Max.   :194.00  
                                                                    
 special_defense      speed             color_1         color_2   
 Min.   : 20.00   Min.   :  5.00   Length   :949   Length   :949  
 1st Qu.: 50.00   1st Qu.: 45.00   N.unique : 18   N.unique : 18  
 Median : 70.00   Median : 65.00   N.blank  :  0   N.blank  :  0  
 Mean   : 72.22   Mean   : 69.02   Min.nchar:  7   Min.nchar:  7  
 3rd Qu.: 90.00   3rd Qu.: 90.00   Max.nchar:  7   Max.nchar:  7  
 Max.   :230.00   Max.   :180.00                   NAs      :439  
                                                                  
      color_f       egg_group_1     egg_group_2       url_icon  
 Length   :949   Length   :949   Length   :949   Length   :949  
 N.unique :155   N.unique : 15   N.unique : 12   N.unique :721  
 N.blank  :  0   N.blank  :  0   N.blank  :  0   N.blank  :  0  
 Min.nchar:  7   Min.nchar:  3   Min.nchar:  3   Min.nchar: 55  
 Max.nchar:  7   Max.nchar: 13   Max.nchar: 13   Max.nchar: 55  
 NAs      :439                   NAs      :711   NAs      :228  
                                                                
 generation_id       url_image  
 Min.   :1.000   Length   :949  
 1st Qu.:2.000   N.unique :949  
 Median :4.000   N.blank  :  0  
 Mean   :3.695   Min.nchar: 83  
 3rd Qu.:5.000   Max.nchar: 85  
 Max.   :7.000                  
 NAs    :147                    

Si quieres ver toda la información puedes usar:

Código
View(pokemon)

En R, la función glimpse() sirve para obtener una vista rápida y compacta de un objeto tipo data frame o tibble: muestra todas las columnas en formato transpuesto, con su nombre, tipo de dato y algunos valores iniciales. Es más legible que print() para tablas anchas y más detallado que str().

Código
glimpse(pokemon)
Rows: 949
Columns: 22
$ id              <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,…
$ pokemon         <chr> "bulbasaur", "ivysaur", "venusaur", "charmander", "cha…
$ species_id      <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,…
$ height          <dbl> 0.7, 1.0, 2.0, 0.6, 1.1, 1.7, 0.5, 1.0, 1.6, 0.3, 0.7,…
$ weight          <dbl> 6.9, 13.0, 100.0, 8.5, 19.0, 90.5, 9.0, 22.5, 85.5, 2.…
$ base_experience <int> 64, 142, 236, 62, 142, 240, 63, 142, 239, 39, 72, 178,…
$ type_1          <chr> "grass", "grass", "grass", "fire", "fire", "fire", "wa…
$ type_2          <chr> "poison", "poison", "poison", NA, NA, "flying", NA, NA…
$ hp              <int> 45, 60, 80, 39, 58, 78, 44, 59, 79, 45, 50, 60, 40, 45…
$ attack          <int> 49, 62, 82, 52, 64, 84, 48, 63, 83, 30, 20, 45, 35, 25…
$ defense         <int> 49, 63, 83, 43, 58, 78, 65, 80, 100, 35, 55, 50, 30, 5…
$ special_attack  <int> 65, 80, 100, 60, 80, 109, 50, 65, 85, 20, 25, 90, 20, …
$ special_defense <int> 65, 80, 100, 50, 65, 85, 64, 80, 105, 20, 25, 80, 20, …
$ speed           <int> 45, 60, 80, 65, 80, 100, 43, 58, 78, 45, 30, 70, 50, 3…
$ color_1         <chr> "#78C850", "#78C850", "#78C850", "#F08030", "#F08030",…
$ color_2         <chr> "#A040A0", "#A040A0", "#A040A0", NA, NA, "#A890F0", NA…
$ color_f         <chr> "#81A763", "#81A763", "#81A763", NA, NA, "#DE835E", NA…
$ egg_group_1     <chr> "monster", "monster", "monster", "monster", "monster",…
$ egg_group_2     <chr> "plant", "plant", "plant", "dragon", "dragon", "dragon…
$ url_icon        <chr> "//archives.bulbagarden.net/media/upload/7/7b/001MS6.p…
$ generation_id   <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
$ url_image       <chr> "https://raw.githubusercontent.com/HybridShivam/Pokemo…

12.3 3. Visualización gráfica

Código
ggplot(pokemon, aes(x = attack, y = defense)) +
  geom_point()