El error que se visualiza en el gráfico para mostrar en orden descendente los barrios, tiene que ver porque algunos de los mismos presentan cruces semafóricos en dos comunas.
ggplot() +
geom_sf(data = barrios_geo, color="black", fill="azure2") +
geom_point(data = semaforizados,
aes(x = long, y = lat, color = comuna), alpha = .4)+
labs(title = "Geolocalización de cruces semaforizados por Comuna",
subtitle = "Ciudad Autónoma de Buenos Aires, 2020",
caption = "Fuente: portal de datos abiertos de la Ciudad - http://data.buenosaires.gob.ar",
y = "",
x = "")

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
## bbox: xmin: -58.53152 ymin: -34.70529 xmax: -58.33514 ymax: -34.52754
## CRS: 4326
head(comunas)
## Simple feature collection with 6 features and 4 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -58.4627 ymin: -34.6625 xmax: -58.33514 ymax: -34.56935
## CRS: 4326
## 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 -...
semaforizados<- semaforizados %>%
filter(!is.na(lat), !is.na(long)) %>%
st_as_sf(coords = c("long", "lat"), crs = 4326)
semaforizados_comunas<- st_join(semaforizados, comunas)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
semaforizados_comunas %>%
group_by(comunas) %>%
summarise(cantidad = n())
## Simple feature collection with 15 features and 2 fields
## geometry type: MULTIPOINT
## dimension: XY
## bbox: xmin: -58.52929 ymin: -34.69513 xmax: -58.35642 ymax: -34.53503
## CRS: EPSG:4326
## # A tibble: 15 x 3
## comunas cantidad geometry
## * <fct> <int> <MULTIPOINT [°]>
## 1 1 592 ((-58.39277 -34.6008), (-58.39219 -34.60563), (-58.39195 -3~
## 2 10 171 ((-58.52929 -34.61721), (-58.52894 -34.6252), (-58.52823 -3~
## 3 11 219 ((-58.52735 -34.61238), (-58.52654 -34.61298), (-58.5251 -3~
## 4 12 259 ((-58.51268 -34.57923), (-58.5125 -34.58111), (-58.51116 -3~
## 5 13 270 ((-58.47542 -34.53933), (-58.4749 -34.53995), (-58.47431 -3~
## 6 14 319 ((-58.44809 -34.56831), (-58.44458 -34.58464), (-58.44444 -~
## 7 15 277 ((-58.50181 -34.59508), (-58.50088 -34.59453), (-58.50073 -~
## 8 2 216 ((-58.41599 -34.59785), (-58.41503 -34.59559), (-58.41463 -~
## 9 3 312 ((-58.41457 -34.60936), (-58.41446 -34.61072), (-58.41393 -~
## 10 4 303 ((-58.43208 -34.64516), (-58.4311 -34.64591), (-58.43087 -3~
## 11 5 238 ((-58.43232 -34.60393), (-58.43107 -34.60215), (-58.4306 -3~
## 12 6 189 ((-58.46154 -34.60663), (-58.46108 -34.61064), (-58.46057 -~
## 13 7 255 ((-58.47547 -34.62744), (-58.47436 -34.62716), (-58.47392 -~
## 14 8 132 ((-58.49671 -34.67366), (-58.49089 -34.6755), (-58.48938 -3~
## 15 9 188 ((-58.52772 -34.63924), (-58.52644 -34.63913), (-58.52563 -~
comunas_semaforizadas<- semaforizados_comunas %>%
filter(!is.na(comunas)) %>%
group_by(comunas) %>%
summarise(cantidad=n())
head(comunas_semaforizadas)
## Simple feature collection with 6 features and 2 fields
## geometry type: MULTIPOINT
## dimension: XY
## bbox: xmin: -58.52929 ymin: -34.64581 xmax: -58.35642 ymax: -34.53503
## CRS: EPSG:4326
## # A tibble: 6 x 3
## comunas cantidad geometry
## <fct> <int> <MULTIPOINT [°]>
## 1 1 592 ((-58.39277 -34.6008), (-58.39219 -34.60563), (-58.39195 -34~
## 2 10 171 ((-58.52929 -34.61721), (-58.52894 -34.6252), (-58.52823 -34~
## 3 11 219 ((-58.52735 -34.61238), (-58.52654 -34.61298), (-58.5251 -34~
## 4 12 259 ((-58.51268 -34.57923), (-58.5125 -34.58111), (-58.51116 -34~
## 5 13 270 ((-58.47542 -34.53933), (-58.4749 -34.53995), (-58.47431 -34~
## 6 14 319 ((-58.44809 -34.56831), (-58.44458 -34.58464), (-58.44444 -3~
comunas_semaforizadas <- st_set_geometry (comunas_semaforizadas, NULL)
comunas <- left_join(comunas, comunas_semaforizadas)
## Joining, by = "comunas"
ggplot() +
geom_sf(data = comunas, aes(fill=( cantidad /area)*10000)) +
geom_sf_text(data=comunas, aes(label = comunas), size=2.5, colour = "black")+
labs(title = "Cantidad de cruces semafóricos por Comuna en relación al área",
subtitle = "Ciudad Autónoma de Buenos Aires, 2020",
fill = "Cantidad por ha ",
caption= "Fuente: portal de datos abiertos de la Ciudad - http://data.buenosaires.gob.ar",
y="",
x="") +
scale_fill_viridis_c()
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data

cantidad_intersecciones <- read.csv("D:/Documents/01-Ditella/Ciencia de Datos2/Clase 1/cantidad_intersecciones33.csv",stringsAsFactors = FALSE, encoding = "UTF-8") %>%
mutate(comunas = as.character (comunas)) %>%
group_by(comunas) %>%
summarise(Total_intersecciones=sum(Cantidad))
cantidad_intersecciones
## # A tibble: 15 x 2
## comunas Total_intersecciones
## <chr> <int>
## 1 1 1425
## 2 10 819
## 3 11 490
## 4 12 585
## 5 13 581
## 6 14 200
## 7 15 903
## 8 2 134
## 9 3 270
## 10 4 518
## 11 5 204
## 12 6 139
## 13 7 301
## 14 8 360
## 15 9 394
comunas <- left_join(comunas, cantidad_intersecciones)
## Joining, by = "comunas"
## Warning: Column `comunas` joining factor and character vector, coercing into
## character vector
ggplot() +
geom_sf(data = comunas, aes(fill=(cantidad / Total_intersecciones) )) +
geom_sf_text(data=comunas, aes(label = comunas), size=2.5, colour = "black")+
labs(title = "Cantidad de cruces semafóricos por Comuna en relación a la cantidad de cruces",
subtitle = "Ciudad Autónoma de Buenos Aires, 2020",
fill = "Cantidad ",
caption= "Fuente: portal de datos abiertos de la Ciudad - http://data.buenosaires.gob.ar/ Libro:BA CAMINA-ANEXO, Cantidad de Cruces",
y="",
x="") +
scale_fill_viridis_c()
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data
