library(sf)
## Linking to GEOS 3.13.0, GDAL 3.8.5, PROJ 9.5.1; sf_use_s2() is TRUE
ggplot(mortalidad) +
geom_col(aes(x = factor(comuna), y = tasa))

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")

nueva_columna <- c("Sur", "Norte", "Sur", "Sur", "Sur", "Norte", "Sur", "Sur",
"Sur", "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 tasa ubicación
## 1 1 3.4 Sur
## 2 2 0.0 Norte
## 3 3 6.0 Sur
## 4 4 7.0 Sur
## 5 5 5.5 Sur
## 6 6 7.5 Norte
ggplot(comunas) +
geom_sf(aes(fill = mortalidad$tasa)) +
geom_sf(data = rivadavia, color = "red") +
scale_fill_distiller(palette = "Spectral")

ggplot(mortalidad) +
geom_col(aes(x = comuna, y = tasa, fill = ubicación)) +
labs(title = "Mortalidad infantil en la Ciudad Autónoma de Buenos Aires",
subtitle = "Año 2020",
y = "tasa")
