##
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
El conjunto de datos starwars proviene del paquete dplyr y contiene información sobre 87 personajes del universo cinematográfico de Star Wars. Las variables incluyen datos físicos (altura, masa, color de ojos, etc.), biográficos (año de nacimiento, planeta de origen, especie), así como listas de las películas, vehículos y naves en las que ha participado cada personaje.
Este dataset fue recopilado como parte del paquete dplyr, utilizado ampliamente en R para manipulación de datos. Los datos provienen de fuentes públicas relacionadas a la franquicia Star Wars, y han sido procesados para facilitar el análisis.
El dataset fue preparado por Hadley Wickham y colaboradores como parte del desarrollo del paquete dplyr. No está vinculado a un artículo académico, sino que fue recopilado de diversas fuentes públicas y fansites sobre Star Wars. Los datos han sido organizados y procesados para facilitar el análisis y la enseñanza en R.
| Variable | Descripción |
|---|---|
| name | Nombre del personaje |
| height | Altura en centímetros |
| mass | Masa corporal en kilogramos |
| hair_color | Color de cabello |
| skin_color | Color de piel |
| eye_color | Color de ojos |
| birth_year | Año de nacimiento (ABY: After Battle of Yavin) |
| sex | Sexo biológico del personaje |
| gender | Identidad de género |
| homeworld | Planeta de origen |
| species | Especie a la que pertenece |
| films | Lista de películas en las que apareció |
| vehicles | Vehículos utilizados por el personaje |
| starships | Naves espaciales utilizadas por el personaje |
| Variable | NA’s | Interpretación breve |
|---|---|---|
| height | 6 | Altura faltante en 6 personajes. Posiblemente droides u otros casos. |
| mass | 28 | Bastantes personajes sin masa registrada. |
| hair_color | 5 | Algunos personajes no tienen cabello. |
| birth_year | 44 | Muchos personajes sin año de nacimiento conocido. |
| sex | 4 | Datos faltantes o indefinidos en sexo. |
| gender | 4 | Coincide con los faltantes en sex. |
| homeworld | 10 | Planeta de origen no registrado para algunos. |
| species | 4 | Especie desconocida o no registrada. |
| films | 0 | Listas completas, aunque algunas vacías. |
| vehicles | 0 | Igual que films, hay algunos personajes sin vehículos. |
| starships | 0 | Algunos personajes no usan naves. |
Al explorar el dataset, se identificaron valores faltantes (NA) en varias variables. Notablemente, la variable birth_year tiene 44 registros sin datos, lo que representa más del 50% del dataset. También se observan NA en mass (28), height (6) y homeworld (10). Esto puede deberse a la naturaleza de algunos personajes (ej. droides) o falta de información en fuentes oficiales.
A partir de la exploración de datos, se observa que:
Los Humanos son mayoría, con una altura media de 178 cm y masa media de 81 kg.
Los personajes masculinos tienen mayor masa promedio que los femeninos.
El planeta Tatooine destaca por tener el mayor número de personajes y apariciones.
Los colores de ojos más comunes son marrón y azul.
Solo 20 personajes utilizan naves espaciales, siendo casi todos humanos.
Se identificaron outliers como Jabba con masa de 1358 kg.
# Vista previa del dataset
head(starwars)
## # A tibble: 6 × 14
## name height mass hair_color skin_color eye_color birth_year sex gender
## <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr>
## 1 Luke Sky… 172 77 blond fair blue 19 male mascu…
## 2 C-3PO 167 75 <NA> gold yellow 112 none mascu…
## 3 R2-D2 96 32 <NA> white, bl… red 33 none mascu…
## 4 Darth Va… 202 136 none white yellow 41.9 male mascu…
## 5 Leia Org… 150 49 brown light brown 19 fema… femin…
## 6 Owen Lars 178 120 brown, gr… light blue 52 male mascu…
## # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>,
## # vehicles <list>, starships <list>
# Dimensiones del dataset
dim(starwars)
## [1] 87 14
# Estructura del dataset
str(starwars)
## tibble [87 × 14] (S3: tbl_df/tbl/data.frame)
## $ name : chr [1:87] "Luke Skywalker" "C-3PO" "R2-D2" "Darth Vader" ...
## $ height : int [1:87] 172 167 96 202 150 178 165 97 183 182 ...
## $ mass : num [1:87] 77 75 32 136 49 120 75 32 84 77 ...
## $ hair_color: chr [1:87] "blond" NA NA "none" ...
## $ skin_color: chr [1:87] "fair" "gold" "white, blue" "white" ...
## $ eye_color : chr [1:87] "blue" "yellow" "red" "yellow" ...
## $ birth_year: num [1:87] 19 112 33 41.9 19 52 47 NA 24 57 ...
## $ sex : chr [1:87] "male" "none" "none" "male" ...
## $ gender : chr [1:87] "masculine" "masculine" "masculine" "masculine" ...
## $ homeworld : chr [1:87] "Tatooine" "Tatooine" "Naboo" "Tatooine" ...
## $ species : chr [1:87] "Human" "Droid" "Droid" "Human" ...
## $ films :List of 87
## ..$ : chr [1:5] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "Revenge of the Sith" ...
## ..$ : chr [1:6] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "The Phantom Menace" ...
## ..$ : chr [1:7] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "The Phantom Menace" ...
## ..$ : chr [1:4] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "Revenge of the Sith"
## ..$ : chr [1:5] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "Revenge of the Sith" ...
## ..$ : chr [1:3] "A New Hope" "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr [1:3] "A New Hope" "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr "A New Hope"
## ..$ : chr "A New Hope"
## ..$ : chr [1:6] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "The Phantom Menace" ...
## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr [1:2] "A New Hope" "Revenge of the Sith"
## ..$ : chr [1:5] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "Revenge of the Sith" ...
## ..$ : chr [1:4] "A New Hope" "The Empire Strikes Back" "Return of the Jedi" "The Force Awakens"
## ..$ : chr "A New Hope"
## ..$ : chr [1:3] "A New Hope" "Return of the Jedi" "The Phantom Menace"
## ..$ : chr [1:3] "A New Hope" "The Empire Strikes Back" "Return of the Jedi"
## ..$ : chr "A New Hope"
## ..$ : chr [1:5] "The Empire Strikes Back" "Return of the Jedi" "The Phantom Menace" "Attack of the Clones" ...
## ..$ : chr [1:5] "The Empire Strikes Back" "Return of the Jedi" "The Phantom Menace" "Attack of the Clones" ...
## ..$ : chr [1:3] "The Empire Strikes Back" "Return of the Jedi" "Attack of the Clones"
## ..$ : chr "The Empire Strikes Back"
## ..$ : chr "The Empire Strikes Back"
## ..$ : chr [1:2] "The Empire Strikes Back" "Return of the Jedi"
## ..$ : chr "The Empire Strikes Back"
## ..$ : chr [1:2] "Return of the Jedi" "The Force Awakens"
## ..$ : chr "Return of the Jedi"
## ..$ : chr "Return of the Jedi"
## ..$ : chr "Return of the Jedi"
## ..$ : chr "Return of the Jedi"
## ..$ : chr "The Phantom Menace"
## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr "The Phantom Menace"
## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr [1:2] "The Phantom Menace" "Attack of the Clones"
## ..$ : chr "The Phantom Menace"
## ..$ : chr "The Phantom Menace"
## ..$ : chr "The Phantom Menace"
## ..$ : chr [1:2] "The Phantom Menace" "Attack of the Clones"
## ..$ : chr "The Phantom Menace"
## ..$ : chr "The Phantom Menace"
## ..$ : chr [1:2] "The Phantom Menace" "Attack of the Clones"
## ..$ : chr "The Phantom Menace"
## ..$ : chr "Return of the Jedi"
## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr "The Phantom Menace"
## ..$ : chr "The Phantom Menace"
## ..$ : chr "The Phantom Menace"
## ..$ : chr "The Phantom Menace"
## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr [1:2] "The Phantom Menace" "Revenge of the Sith"
## ..$ : chr [1:2] "The Phantom Menace" "Revenge of the Sith"
## ..$ : chr [1:2] "The Phantom Menace" "Revenge of the Sith"
## ..$ : chr "The Phantom Menace"
## ..$ : chr [1:3] "The Phantom Menace" "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr [1:2] "The Phantom Menace" "Attack of the Clones"
## ..$ : chr "Attack of the Clones"
## ..$ : chr "Attack of the Clones"
## ..$ : chr "Attack of the Clones"
## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr "Attack of the Clones"
## ..$ : chr "Attack of the Clones"
## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr "Attack of the Clones"
## ..$ : chr "Attack of the Clones"
## ..$ : chr "Attack of the Clones"
## ..$ : chr "Attack of the Clones"
## ..$ : chr "Attack of the Clones"
## ..$ : chr "Attack of the Clones"
## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr "Attack of the Clones"
## ..$ : chr "Attack of the Clones"
## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr "Revenge of the Sith"
## ..$ : chr "Revenge of the Sith"
## ..$ : chr [1:2] "A New Hope" "Revenge of the Sith"
## ..$ : chr [1:2] "Attack of the Clones" "Revenge of the Sith"
## ..$ : chr "Revenge of the Sith"
## ..$ : chr "The Force Awakens"
## ..$ : chr "The Force Awakens"
## ..$ : chr "The Force Awakens"
## ..$ : chr "The Force Awakens"
## ..$ : chr "The Force Awakens"
## $ vehicles :List of 87
## ..$ : chr [1:2] "Snowspeeder" "Imperial Speeder Bike"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Imperial Speeder Bike"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Tribubble bongo"
## ..$ : chr [1:2] "Zephyr-G swoop bike" "XJ-6 airspeeder"
## ..$ : chr(0)
## ..$ : chr "AT-ST"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Snowspeeder"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Tribubble bongo"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Sith speeder"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Flitknot speeder"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Koro-2 Exodrive airspeeder"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Tsmeu-6 personal wheel bike"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## $ starships :List of 87
## ..$ : chr [1:2] "X-wing" "Imperial shuttle"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "TIE Advanced x1"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "X-wing"
## ..$ : chr [1:5] "Jedi starfighter" "Trade Federation cruiser" "Naboo star skiff" "Jedi Interceptor" ...
## ..$ : chr [1:3] "Naboo fighter" "Trade Federation cruiser" "Jedi Interceptor"
## ..$ : chr(0)
## ..$ : chr [1:2] "Millennium Falcon" "Imperial shuttle"
## ..$ : chr [1:2] "Millennium Falcon" "Imperial shuttle"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "X-wing"
## ..$ : chr "X-wing"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Slave 1"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Millennium Falcon"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "A-wing"
## ..$ : chr(0)
## ..$ : chr "Millennium Falcon"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr [1:3] "Naboo fighter" "H-type Nubian yacht" "Naboo star skiff"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Naboo Royal Starship"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Scimitar"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Jedi starfighter"
## ..$ : chr(0)
## ..$ : chr "Naboo fighter"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "Belbullab-22 starfighter"
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr(0)
## ..$ : chr "X-wing"
## ..$ : chr(0)
## ..$ : chr(0)
# Aux que nos servirá para graficas finales
peso_categoria <- starwars %>%
mutate(categoria_peso = case_when(
mass < 50 ~ "Ligero",
mass >= 50 & mass < 100 ~ "Medio",
mass >= 100 ~ "Pesado",
TRUE ~ "Desconocido"
)) %>%
select(name, categoria_peso)
starwars_joined <- left_join(starwars, peso_categoria, by = "name")
humanos_filtrados <- starwars_joined %>%
filter(species == "Human", !is.na(height), !is.na(mass))
plot(humanos_filtrados$height, humanos_filtrados$mass,
main = "Altura vs Masa en Humanos (por categoría de peso)",
xlab = "Altura (cm)", ylab = "Masa (kg)",
col = ifelse(humanos_filtrados$categoria_peso == "Ligero", "green",
ifelse(humanos_filtrados$categoria_peso == "Medio", "blue", "red")
),
pch = 19
)
legend("topright",
legend = c("Ligero", "Medio", "Pesado"),
col = c("green", "blue", "red"), pch = 19
)
Esta gráfica muestra cómo se relacionan la altura y la masa de los personajes humanos, agrupados por su categoría de peso. La mayoría pertenece a la categoría media, mientras que pocos son ligeros o pesados. Se observa una distribución homogénea en altura, pero los de mayor peso se destacan visualmente.
planetas_peliculas <- starwars %>%
mutate(n_films = lengths(films)) %>%
group_by(homeworld) %>%
summarise(total_peliculas = sum(n_films, na.rm = TRUE)) %>%
arrange(desc(total_peliculas)) %>%
filter(!is.na(homeworld)) %>%
head(10)
barplot(planetas_peliculas$total_peliculas,
names.arg = planetas_peliculas$homeworld,
main = "Top 10 Planetas por Total de Apariciones en Películas",
xlab = "Planeta", ylab = "Total de Apariciones",
las = 2, col = "orange", cex.names = 0.8
)
Este gráfico representa los 10 planetas más relevantes según la cantidad de películas en que aparecen sus personajes. Tatooine es el más destacado, lo que refuerza su importancia en la saga, seguido por Naboo y Alderaan.
graficar_dispersión <- function(var_x, var_y, titulo = "", color = "purple") {
plot(var_x, var_y,
main = titulo,
xlab = deparse(substitute(var_x)),
ylab = deparse(substitute(var_y)),
col = color, pch = 19
)
}
La exploración detallada de este conjunto permitió identificar patrones físicos y biográficos entre personajes, así como su participación en la narrativa de Star Wars. Esta base nos permitió definir visualizaciones que reflejan tanto la diversidad de especies y planetas, como la importancia de ciertos personajes según sus características.