1 Nuestro primer proyecto en R
sqrt(144)
## [1] 12
mensaje <- "Hola mundo"
mensaje
## [1] "Hola mundo"
x <- 8 * 6
x
## [1] 48
ancho_habitacion_m <- 8
profundiad_habitacion_m <- 6
superficie_habitacion_m2 <- ancho_habitacion_m * profundiad_habitacion_m
superficie_habitacion_m2
## [1] 48
2.1.4 Cargar los datos
mortalidad <- read.csv('https://cdaj.netlify.app/data/mortalidad_infantil_caba_2020.csv')
mortalidad
## Comuna Tasa2020
## 1 1 5.9
## 2 2 3.6
## 3 3 3.1
## 4 4 8.7
## 5 5 6.2
## 6 6 2.8
## 7 7 6.1
## 8 8 3.7
## 9 9 7.5
## 10 10 3.1
## 11 11 2.9
## 12 12 1.1
## 13 13 3.0
## 14 14 4.0
## 15 15 2.6
dim(mortalidad)
## [1] 15 2
names(mortalidad)
## [1] "Comuna" "Tasa2020"
head(mortalidad)
## Comuna Tasa2020
## 1 1 5.9
## 2 2 3.6
## 3 3 3.1
## 4 4 8.7
## 5 5 6.2
## 6 6 2.8
2.2 Visualización: la exploración gráfica de la información
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
ggplot(mortalidad) +
geom_col(aes(x = factor(Comuna), y = Tasa2020))
2.2.1 Haciendo mapas
library(sf)
## Linking to GEOS 3.14.1, GDAL 3.12.1, PROJ 9.7.1; sf_use_s2() is TRUE
comunas <- st_read('https://bitsandbricks.github.io/data/CABA_comunas.geojson')
## Reading layer `CABA_comunas' from data source
## `https://bitsandbricks.github.io/data/CABA_comunas.geojson'
## using driver `GeoJSON'
## Simple feature collection with 15 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -58.53152 ymin: -34.70529 xmax: -58.33514 ymax: -34.52754
## Geodetic CRS: WGS 84
dim(comunas)
## [1] 15 5
names(comunas)
## [1] "barrios" "perimetro" "area" "comunas" "geometry"
head(comunas)
## Simple feature collection with 6 features and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -58.4627 ymin: -34.6625 xmax: -58.33514 ymax: -34.56935
## Geodetic CRS: WGS 84
## barrios
## 1 CONSTITUCION - MONSERRAT - PUERTO MADERO - RETIRO - SAN NICOLAS - SAN TELMO
## 2 RECOLETA
## 3 BALVANERA - SAN CRISTOBAL
## 4 BARRACAS - BOCA - NUEVA POMPEYA - PARQUE PATRICIOS
## 5 ALMAGRO - BOEDO
## 6 CABALLITO
## perimetro area comunas geometry
## 1 35572.65 17802807 1 MULTIPOLYGON (((-58.36854 -...
## 2 21246.61 6140873 2 MULTIPOLYGON (((-58.39521 -...
## 3 10486.26 6385991 3 MULTIPOLYGON (((-58.41192 -...
## 4 36277.44 21701236 4 MULTIPOLYGON (((-58.3552 -3...
## 5 12323.47 6660526 5 MULTIPOLYGON (((-58.41287 -...
## 6 10990.96 6851029 6 MULTIPOLYGON (((-58.43061 -...
ggplot(comunas) +
geom_sf()
ggplot(comunas) +
geom_sf(aes(fill = comunas))
rivadavia <- st_read('https://bitsandbricks.github.io/data/avenida_rivadavia.geojson')
## Reading layer `avenida_rivadavia' from data source
## `https://bitsandbricks.github.io/data/avenida_rivadavia.geojson'
## using driver `GeoJSON'
## Simple feature collection with 1 feature and 1 field
## Geometry type: LINESTRING
## Dimension: XY
## Bounding box: xmin: -58.53014 ymin: -34.63946 xmax: -58.37017 ymax: -34.60711
## Geodetic CRS: WGS 84
ggplot(comunas) +
geom_sf(aes(fill = comunas)) +
geom_sf(data = rivadavia, color = "red")
2.2.2 Agregando datos
nueva_columna <- c("Sur", "Norte", "Sur", "Sur", "Sur", "Norte", "Sur", "Sur",
"Sur", "Norte", "Norte", "Norte", "Norte", "Norte", "Norte")
nueva_columna
## [1] "Sur" "Norte" "Sur" "Sur" "Sur" "Norte" "Sur" "Sur" "Sur"
## [10] "Norte" "Norte" "Norte" "Norte" "Norte" "Norte"
comunas <- mutate(comunas, ubicacion = nueva_columna)
head(comunas)
## Simple feature collection with 6 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -58.4627 ymin: -34.6625 xmax: -58.33514 ymax: -34.56935
## Geodetic CRS: WGS 84
## barrios
## 1 CONSTITUCION - MONSERRAT - PUERTO MADERO - RETIRO - SAN NICOLAS - SAN TELMO
## 2 RECOLETA
## 3 BALVANERA - SAN CRISTOBAL
## 4 BARRACAS - BOCA - NUEVA POMPEYA - PARQUE PATRICIOS
## 5 ALMAGRO - BOEDO
## 6 CABALLITO
## perimetro area comunas geometry ubicacion
## 1 35572.65 17802807 1 MULTIPOLYGON (((-58.36854 -... Sur
## 2 21246.61 6140873 2 MULTIPOLYGON (((-58.39521 -... Norte
## 3 10486.26 6385991 3 MULTIPOLYGON (((-58.41192 -... Sur
## 4 36277.44 21701236 4 MULTIPOLYGON (((-58.3552 -3... Sur
## 5 12323.47 6660526 5 MULTIPOLYGON (((-58.41287 -... Sur
## 6 10990.96 6851029 6 MULTIPOLYGON (((-58.43061 -... Norte
ggplot(comunas) +
geom_sf(aes(fill = ubicacion)) +
geom_sf(data = rivadavia, color = "red")
mortalidad <- mutate(mortalidad, ubicación = nueva_columna)
head(mortalidad)
## Comuna Tasa2020 ubicación
## 1 1 5.9 Sur
## 2 2 3.6 Norte
## 3 3 3.1 Sur
## 4 4 8.7 Sur
## 5 5 6.2 Sur
## 6 6 2.8 Norte
2.3 El veredicto final
ggplot(comunas) +
geom_sf(aes(fill = mortalidad$Tasa2020)) +
geom_sf(data = rivadavia, color = "red") +
scale_fill_distiller(palette = "Spectral")
ggplot(mortalidad) +
geom_col(aes(x = Comuna, y = Tasa2020, fill = ubicación)) +
labs(title = "Mortalidad infantil en la Ciudad Autónoma de Buenos Aires",
subtitle = "Año 2020",
y = "tasa")
2.3.1 ¿Cuál es la diferencia en mortalidad infantil entre el sur y el norte de la Ciudad Autónoma de Buenos Aires?
En base a lo que descubrimos, vamos a responder en forma sucinta:
Según los registros del año 2020, la tasa de mortalidad infantil en cada uno de los barrios del sur es más alta que en cualquiera de los del norte
EJERCICIO
I. Descarguemos un dataset en formato csv. Pueden recurrir al portal de datos abiertos de su ciudad, o a cualquier otro repositorio público, como el de bases de datos del Banco Mundial.
Data Set elegido: “Trayectoria Educativa” publicado por el Ministerio de Educación de la Provincia de Córdoba (Fuente: https://datosgestionabierta.cba.gov.ar/dataset/trayectoria-educativa)
Descripción: Las Estadísticas de trayectoria educativa reflejan para cada ciclo lectivo el proceso educativo de los alumnos. Incluye los matriculados al inicio y final del ciclo lectivo, los alumnos entrados y salidos durante el ciclo a otras instituciones, y el total de promovidos y no promovidos al siguiente curso. Los datos se presentan con apertura por departamento de la provincia de Córdoba para los niveles Primario y Secundario.
Última actualización: 27 de agosto de 2026, 11:08 (UTC-03:00) Creado: 16 de mayo de 2025, 10:32 (UTC-03:00) Frecuencia de actualización Anual
Trayectoria_Educativa <- read.csv("C:/Users/pedro/Downloads/10.3-trayectoria-educativa-bd.csv")
head(Trayectoria_Educativa)
## ciclo_lectivo id_departamento n_departamento n_modalidad n_nivel.n_oferta
## 1 2024 14007 CALAMUCHITA Comun Primario
## 2 2024 14007 CALAMUCHITA Comun Secundario
## 3 2024 14014 CAPITAL Comun Primario
## 4 2024 14014 CAPITAL Comun Secundario
## 5 2024 14021 COLON Comun Primario
## 6 2024 14021 COLON Comun Secundario
## mat_ini entrados salidos mat_fin promovidos no_prom
## 1 7272 258 248 7274 7221 53
## 2 7338 213 342 7210 6292 918
## 3 134105 3204 3688 133607 132966 641
## 4 133096 2768 4225 131637 113865 17772
## 5 28065 665 685 28041 27945 96
## 6 27238 439 846 26831 22944 3887
names(Trayectoria_Educativa)
## [1] "ciclo_lectivo" "id_departamento" "n_departamento" "n_modalidad"
## [5] "n_nivel.n_oferta" "mat_ini" "entrados" "salidos"
## [9] "mat_fin" "promovidos" "no_prom"
dim(Trayectoria_Educativa)
## [1] 260 11
summary(Trayectoria_Educativa)
## ciclo_lectivo id_departamento n_departamento n_modalidad
## Min. :2020 Min. :14007 Length :260 Length :260
## 1st Qu.:2021 1st Qu.:14049 N.unique : 26 N.unique : 1
## Median :2022 Median :14094 N.blank : 0 N.blank : 0
## Mean :2022 Mean :14094 Min.nchar: 5 Min.nchar: 5
## 3rd Qu.:2023 3rd Qu.:14140 Max.nchar: 27 Max.nchar: 5
## Max. :2024 Max. :14182
## n_nivel.n_oferta mat_ini entrados salidos
## Length :260 Min. : 343 Min. : 0.0 Min. : 0.00
## N.unique : 2 1st Qu.: 3220 1st Qu.: 40.5 1st Qu.: 70.75
## N.blank : 0 Median : 6572 Median : 119.5 Median : 172.50
## Min.nchar: 8 Mean : 13463 Mean : 275.1 Mean : 380.31
## Max.nchar: 10 3rd Qu.: 12565 3rd Qu.: 285.8 3rd Qu.: 392.25
## Max. :141785 Max. :3204.0 Max. :4416.00
## mat_fin promovidos no_prom
## Min. : 334 Min. : 291 Min. : 0.0
## 1st Qu.: 3186 1st Qu.: 2756 1st Qu.: 21.5
## Median : 6483 Median : 6340 Median : 122.5
## Mean : 13354 Mean : 12489 Mean : 864.2
## 3rd Qu.: 12505 3rd Qu.: 11238 3rd Qu.: 847.2
## Max. :141422 Max. :141141 Max. :18838.0