*1. Deberán elegir una ciudad en cualquier parte del mundo que les interese (ya que seguirán trabajando con ella) y que disponga de un portal de datos abiertos que ofrece un shapefile con sus barrios.
Ciudad elegida: CABA
library(tidyverse)
## -- Attaching packages -------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.0 v purrr 0.3.4
## v tibble 3.0.1 v dplyr 0.8.5
## v tidyr 1.0.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ----------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(geosphere)
library(dbscan)
library(ggmap)
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(ggrepel)
Cargo dataset barrios porteños
barrios <- st_read('http://cdn.buenosaires.gob.ar/datosabiertos/datasets/barrios/barrios.geojson')
## Reading layer `barrios_badata' from data source `http://cdn.buenosaires.gob.ar/datosabiertos/datasets/barrios/barrios.geojson' using driver `GeoJSON'
## Simple feature collection with 48 features and 4 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -58.53152 ymin: -34.70529 xmax: -58.33515 ymax: -34.52649
## geographic CRS: WGS 84
names(barrios)
## [1] "barrio" "comuna" "perimetro" "area" "geometry"
2. Del mismo portal de datos, o de otra fuente si la tienen, elegirán un dataset con registros geo-referenciados. Por ejemplo, las escuelas de la ciudad (o las comisarías, o las propiedades en alquiler, o…) con sus coordenadas. Seleccionamos centros de vacunacion para adultos mayores.
Cargo dataset de vacunatorios para adultos
vacunatorios_adultos <-st_read('http://cdn.buenosaires.gob.ar/datosabiertos/datasets/vacunatorios-adultos-mayores/vacunatorios-adultos-mayores.geojson')
## Reading layer `vacunacion' from data source `http://cdn.buenosaires.gob.ar/datosabiertos/datasets/vacunatorios-adultos-mayores/vacunatorios-adultos-mayores.geojson' using driver `GeoJSON'
## Simple feature collection with 80 features and 6 fields
## geometry type: POINT
## dimension: XY
## bbox: xmin: -58.5253 ymin: -34.68989 xmax: -58.37062 ymax: -34.54537
## geographic CRS: WGS 84
names(vacunatorios_adultos)
## [1] "nombre" "barrio" "comuna" "tipo" "domicilio" "aph"
## [7] "geometry"
3. Realizando un join espacial, asignar a cada registro geo-referenciado la comuna que le corresponde. Combinamos datasets con información espacial de vacunatorios para adultos mayores y comunas.
ggplot() +
geom_sf(data = barrios) +
geom_sf(data = vacunatorios_adultos, color = "red", alpha = .4)
vacunatorios_barrios <- st_join(barrios, vacunatorios_adultos)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
head(vacunatorios_barrios)
## Simple feature collection with 6 features and 10 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -58.47883 ymin: -34.60762 xmax: -58.42337 ymax: -34.57829
## geographic CRS: WGS 84
## barrio.x comuna.x perimetro area nombre
## 1 CHACARITA 15 7724.853 3115707 Carlos Gardel
## 1.1 CHACARITA 15 7724.853 3115707 Baldomero Fernández Moreno
## 2 PATERNAL 15 7087.513 2229829 Santa Inés Virgen y Mártir
## 3 VILLA CRESPO 15 8131.857 3615978 Centro de dia 15
## 3.1 VILLA CRESPO 15 8131.857 3615978 Esc. de Educación Media N° 03/07°
## 3.2 VILLA CRESPO 15 8131.857 3615978 Casa de la Lectura
## barrio.y comuna.y tipo domicilio
## 1 CHACARITA 15 Espacio cultural Olleros 3640
## 1.1 CHACARITA 15 Espacio cultural Concepción Arenal 4206
## 2 PATERNAL 15 Iglesia Ávalos 250
## 3 VILLA CRESPO 15 Centro de día Jufre 350
## 3.1 VILLA CRESPO 15 Escuela Padilla 1051
## 3.2 VILLA CRESPO 15 Espacio cultural Lavalleja 924
## aph geometry
## 1 HTAL. DR. E. TORNÚ POLYGON ((-58.45282 -34.595...
## 1.1 HTAL. DR. E. TORNÚ POLYGON ((-58.45282 -34.595...
## 2 HTAL. DR. E. TORNÚ POLYGON ((-58.46558 -34.596...
## 3 HTAL. DR. C.G. DURAND POLYGON ((-58.42375 -34.597...
## 3.1 HTAL. DR. C.G. DURAND POLYGON ((-58.42375 -34.597...
## 3.2 HTAL. DR. C.G. DURAND POLYGON ((-58.42375 -34.597...
Creamos un nuevo dataset con las variables que nos interesa analizar, nombrándola vacunatorios_barrios
cantidad_vacunatorios <- vacunatorios_barrios %>%
group_by(barrio.x) %>%
summarise(cantidad = n())
head(cantidad_vacunatorios)
## Simple feature collection with 6 features and 2 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -58.50354 ymin: -34.66226 xmax: -58.33515 ymax: -34.53168
## geographic CRS: WGS 84
## # A tibble: 6 x 3
## barrio.x cantidad geometry
## <chr> <int> <POLYGON [°]>
## 1 AGRONOMIA 1 ((-58.47712 -34.59511, -58.47788 -34.59709, -58.47835 -34.~
## 2 ALMAGRO 2 ((-58.41287 -34.61412, -58.41282 -34.61544, -58.41275 -34.~
## 3 BALVANERA 2 ((-58.41192 -34.598, -58.41029 -34.59809, -58.40943 -34.59~
## 4 BARRACAS 1 ((-58.37034 -34.63293, -58.37028 -34.63339, -58.37025 -34.~
## 5 BELGRANO 4 ((-58.45057 -34.53561, -58.45066 -34.53564, -58.45075 -34.~
## 6 BOCA 1 ((-58.35429 -34.62977, -58.35427 -34.62981, -58.35421 -34.~
4. Utilizando ggplot() realizar
** Ambos dataset presentan las variables de comunas y barrios Realizamos un join espacial de las variables de vacunatorios adultos y geriatricos
Realizamos grafico donde se ven los vacunatorios por comuna
ggplot() +
geom_sf(data = barrios) +
geom_sf(data = vacunatorios_adultos, aes(color = barrio))
Creamos gráfico de barras mostrando cantidad de vacunatorios para adultosmayores por barrio
ggplot(cantidad_vacunatorios) +
geom_bar(aes(x = barrio.x, weight = cantidad, color = cantidad, fill = barrio.x)) +
coord_flip() +
labs(title = "Centros de vacunacion de adultos mayores por comuna",
subtitle = "Ciudad Autónoma de Buenos Aires",
caption = "Fuente: portal de datos abiertos de la Ciudad - http://data.buenosaires.gob.ar",
x = "barrio",
y = "cantidad",
fill = "barrio")
Procederemos ahora a realizar un mapa con los límites de los barrios, cuyo color de relleno indique la cantidad de centros vacunatorios para adultos mayores encontrada en cada barrio.
cantidad_vacunatorios <- vacunatorios_barrios %>%
group_by(barrio.x) %>%
summarise(cantidad = n())
head(cantidad_vacunatorios)
## Simple feature collection with 6 features and 2 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -58.50354 ymin: -34.66226 xmax: -58.33515 ymax: -34.53168
## geographic CRS: WGS 84
## # A tibble: 6 x 3
## barrio.x cantidad geometry
## <chr> <int> <POLYGON [°]>
## 1 AGRONOMIA 1 ((-58.47712 -34.59511, -58.47788 -34.59709, -58.47835 -34.~
## 2 ALMAGRO 2 ((-58.41287 -34.61412, -58.41282 -34.61544, -58.41275 -34.~
## 3 BALVANERA 2 ((-58.41192 -34.598, -58.41029 -34.59809, -58.40943 -34.59~
## 4 BARRACAS 1 ((-58.37034 -34.63293, -58.37028 -34.63339, -58.37025 -34.~
## 5 BELGRANO 4 ((-58.45057 -34.53561, -58.45066 -34.53564, -58.45075 -34.~
## 6 BOCA 1 ((-58.35429 -34.62977, -58.35427 -34.62981, -58.35421 -34.~
ggplot() +
geom_sf(data = cantidad_vacunatorios, aes(fill=cantidad)) +
labs(title = "Vacunatorios para adultos",
subtitle = "Ciudad Autonoma de Buenos Aires",
fill = "Cantidad",
caption= "Fuente: https://data.buenosaires.gob.ar/",
y="latitud",
x="longitud") +
scale_fill_gradient(low="pink", high="red")
Cargamos nuevas librerias
library(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(leaflet)
A continuacion obtener la bounding box Palermo con la función getbb()
bbox_st <- getbb('Palermo, Ciudad Autonoma de Buenos Aires')
bbox_st_poly = getbb('Palermo, Ciudad Autonoma de Buenos Aires', format_out = "sf_polygon")
leaflet(bbox_st_poly) %>%
addTiles() %>%
addPolygons()
Solicitaremos las vias de circulacion de Palermo
Palermo_calles <- opq(bbox_st) %>%
add_osm_feature(key = "highway") %>%
osmdata_sf()
Palermo_calles <- st_intersection(Palermo_calles$osm_lines, bbox_st_poly)
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
Palermo_calles <- Palermo_calles %>%
mutate(lanes = as.numeric(lanes))
Realizamos un mapa de las calles de Palorme de acuerdo vias de circulacion(tipo de carril)
ggplot(Palermo_calles) +
geom_sf(aes(color = lanes), alpha = 0.5) +
scale_fill_continuous() + theme_void()+
labs(title = "Palermo",
subtitle = "Vías de circulación",
caption = "fuente: OpenStreetMap",
color = "cantidad de carriles")
Descargar de OpenStreetMap una (o más) capas de datos de tipo puntos o polígonos. (Ver catálogo de categorías en https://wiki.openstreetmap.org/wiki/Map_Features)
En este caso elegimos hospitales en Palermo
Palermo_hospitales <- opq(bbox_st) %>%
add_osm_feature(key = "amenity", value = "hospital") %>%
osmdata_sf()
Palermo_hospitales <- st_intersection(Palermo_hospitales$osm_points, bbox_st_poly)
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
Proyectar los datos descargados en un mapa y comentar los resultados: ¿Cómo se distribuyen en la Ciudad?
ggplot() +
geom_sf(data = Palermo_calles, color = "gray60", alpha = .8) +
geom_sf(data = Palermo_hospitales, color= "red", alpha=.8) +
theme_void() +
labs(title = "Hospitales",
subtitle = "Palermo",
caption = "fuente: OpenStreetMap")
Hacer un conteo de los ítems de la capa descargada por barrio, mapearlo y compararlo con el conteo de los ítems descargados en el ejercicio anterior: ¿La distribución es similar o hay diferencias? ¿A qué se puede deber?
Ahora cargamos el mapa de toda la ciudad, para poder comparar con el item del ejercicio anterior que abarcaba todo CABA
bbox_st_caba <- getbb('Ciudad Autonoma de Buenos Aires')
bbox_st_poly_caba = getbb('Ciudad Autonoma de Buenos Aires', format_out = "sf_polygon")
Hospitales <- opq(bbox_st_caba) %>%
add_osm_feature(key = "amenity", value = "hospital") %>%
osmdata_sf()
hospitales_caba <- st_intersection(Hospitales$osm_points, bbox_st_poly_caba)
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
hospitales_caba_barrios <- st_join(hospitales_caba,barrios)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
hvb <- hospitales_caba_barrios %>%
group_by(barrio) %>%
summarise(cantidad = n())
hvb <- hvb %>%
st_set_geometry(NULL)
hospitales_vac_barrios <- barrios %>%
left_join(hvb, by="barrio")
ggplot() +
geom_sf(data=hospitales_vac_barrios, aes(fill=cantidad)) +
geom_sf_text(data=hospitales_vac_barrios, aes(label = cantidad ), size=2, colour = "blue")+
labs(title = "Hospitales en Caba",
subtitle = "Palermo",
fill = "Cantidad",
caption= "Fuente: https://datos.caba.gob.ar / OpenStreetMap",
y="latitud",
x="longitud") +
scale_fill_gradient(low="yellow", high="red")
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data
## Warning: Removed 15 rows containing missing values (geom_text).
Cargamos nuevas librerias
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:dplyr':
##
## intersect, setdiff, union
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(ggmap)
library(rtweet)
##
## Attaching package: 'rtweet'
## The following object is masked from 'package:purrr':
##
## flatten
I. Descargar tweets que se originen en los alrededores de la Ciudad con la que están trabajando, y explorar las columnas/variables que contiene.
tweets_rmba <- read.csv("C:/Users/Maria/Downloads/ciencia de datos/tweets_rmba.csv")
tweets_rmba <- sample_frac(tweets_rmba, 0.01)
II. Analizar: a. ¿Cuáles son los mensajes con más repercusión? ¿Qué dicen? b. ¿En qué momento del día se realiza la mayor cantidad de tweets? Graficar. c. ¿Cómo se distribuye la popularidad de los usuarios? ¿Quiénes son los 5 que más seguidores tienen? Graficar. d. Aislando los tweets que poseen coordenadas geográficas (lat y long), crear mapas que muestren posición de los tweets y cantidad de seguidores del usuario que tuitea
Momento en el que se realizan mayor cantidad de tweets
tweets_rmba <- tweets_rmba %>%
mutate(created=ymd_hms(created))
ts_plot(tweets_rmba, "month")
A través de este grafico se observa la una mayor produccion de tweets en el mes de octubre
Los 5 usuarios con mas popularidad
tweets_rmba %>%
top_n(5, user_followers) %>%
arrange(desc(user_followers)) %>%
select(user_name, user_followers, user_location, text)
## user_name user_followers user_location
## 1 Norkys_batista 2524245 VENEZUELA
## 2 pelanza 1565691 São Paulo
## 3 kndmolfese 1130393
## 4 yanilatorre 894081
## 5 andrearincontop 782480 Argentina
## text
## 1 Asiii se ve a esta hora el #TeatroOpera aquiiiii en #BuenosAires #ArgentinaJujuuuuuuyyyyy ARMAâ\200¦ https://t.co/ooYER0WtfS
## 2 #TBT da minha última passagem por Buenos Aires, em Novembro do ano passado.\nUma pequenaâ\200¦ https://t.co/twlIzhJ6Xj
## 3 Las tardes de verano en Bs As â\235¤ï¸\217 Sábado a puro paseo y relax ðŸ\230Ž Ustedes en que andan? en Ciudadâ\200¦ https://t.co/hwLAWiBP0M
## 4 Sos lo mas @Martosalwe en Artear Canal 13 https://t.co/XKiIRtw3s8
## 5 Creà que estaba sólay no era cierto... 🎶 Hay equipo 💪gastonpauls22 @arielstaltari @ortegajuliâ\200¦ https://t.co/fv6msUxdBp
Aqui podemos ver los usuarios mas populares en el top n 5.
Grafico de los usuarios con mas followers
options(scipen = 20)
ggplot(tweets_rmba) +
geom_histogram(aes(x = user_followers))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Grafico a otra escala para mejor observación
ggplot(tweets_rmba) +
geom_histogram(aes(x = user_followers))+
scale_x_log10()
## Warning: Transformation introduced infinite values in continuous x-axis
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 8 rows containing non-finite values (stat_bin).
En este histograma se puede observar que la mayoria de los usuarios tienen entre 800 y 1000 seguidores.
Mapas que muestren posición de los tweets y cantidad de seguidores del usuario que tuitea
tweets_rmba <- lat_lng(tweets_rmba)
tweets_rmba <- tweets_rmba %>%
select(-geo_coords, -coords_coords, -bbox_coords)
nrow(tweets_rmba)
## [1] 8637
bbox <- make_bbox(lon = tweets_rmba$X, lat = tweets_rmba$Y)
mimapa <- get_stamenmap(bbox, zoom = 11)
## 100 tiles needed, this may take a while (try a smaller zoom).
## Source : http://tile.stamen.com/terrain/11/686/1229.png
## Source : http://tile.stamen.com/terrain/11/687/1229.png
## Source : http://tile.stamen.com/terrain/11/688/1229.png
## Source : http://tile.stamen.com/terrain/11/689/1229.png
## Source : http://tile.stamen.com/terrain/11/690/1229.png
## Source : http://tile.stamen.com/terrain/11/691/1229.png
## Source : http://tile.stamen.com/terrain/11/692/1229.png
## Source : http://tile.stamen.com/terrain/11/693/1229.png
## Source : http://tile.stamen.com/terrain/11/694/1229.png
## Source : http://tile.stamen.com/terrain/11/695/1229.png
## Source : http://tile.stamen.com/terrain/11/686/1230.png
## Source : http://tile.stamen.com/terrain/11/687/1230.png
## Source : http://tile.stamen.com/terrain/11/688/1230.png
## Source : http://tile.stamen.com/terrain/11/689/1230.png
## Source : http://tile.stamen.com/terrain/11/690/1230.png
## Source : http://tile.stamen.com/terrain/11/691/1230.png
## Source : http://tile.stamen.com/terrain/11/692/1230.png
## Source : http://tile.stamen.com/terrain/11/693/1230.png
## Source : http://tile.stamen.com/terrain/11/694/1230.png
## Source : http://tile.stamen.com/terrain/11/695/1230.png
## Source : http://tile.stamen.com/terrain/11/686/1231.png
## Source : http://tile.stamen.com/terrain/11/687/1231.png
## Source : http://tile.stamen.com/terrain/11/688/1231.png
## Source : http://tile.stamen.com/terrain/11/689/1231.png
## Source : http://tile.stamen.com/terrain/11/690/1231.png
## Source : http://tile.stamen.com/terrain/11/691/1231.png
## Source : http://tile.stamen.com/terrain/11/692/1231.png
## Source : http://tile.stamen.com/terrain/11/693/1231.png
## Source : http://tile.stamen.com/terrain/11/694/1231.png
## Source : http://tile.stamen.com/terrain/11/695/1231.png
## Source : http://tile.stamen.com/terrain/11/686/1232.png
## Source : http://tile.stamen.com/terrain/11/687/1232.png
## Source : http://tile.stamen.com/terrain/11/688/1232.png
## Source : http://tile.stamen.com/terrain/11/689/1232.png
## Source : http://tile.stamen.com/terrain/11/690/1232.png
## Source : http://tile.stamen.com/terrain/11/691/1232.png
## Source : http://tile.stamen.com/terrain/11/692/1232.png
## Source : http://tile.stamen.com/terrain/11/693/1232.png
## Source : http://tile.stamen.com/terrain/11/694/1232.png
## Source : http://tile.stamen.com/terrain/11/695/1232.png
## Source : http://tile.stamen.com/terrain/11/686/1233.png
## Source : http://tile.stamen.com/terrain/11/687/1233.png
## Source : http://tile.stamen.com/terrain/11/688/1233.png
## Source : http://tile.stamen.com/terrain/11/689/1233.png
## Source : http://tile.stamen.com/terrain/11/690/1233.png
## Source : http://tile.stamen.com/terrain/11/691/1233.png
## Source : http://tile.stamen.com/terrain/11/692/1233.png
## Source : http://tile.stamen.com/terrain/11/693/1233.png
## Source : http://tile.stamen.com/terrain/11/694/1233.png
## Source : http://tile.stamen.com/terrain/11/695/1233.png
## Source : http://tile.stamen.com/terrain/11/686/1234.png
## Source : http://tile.stamen.com/terrain/11/687/1234.png
## Source : http://tile.stamen.com/terrain/11/688/1234.png
## Source : http://tile.stamen.com/terrain/11/689/1234.png
## Source : http://tile.stamen.com/terrain/11/690/1234.png
## Source : http://tile.stamen.com/terrain/11/691/1234.png
## Source : http://tile.stamen.com/terrain/11/692/1234.png
## Source : http://tile.stamen.com/terrain/11/693/1234.png
## Source : http://tile.stamen.com/terrain/11/694/1234.png
## Source : http://tile.stamen.com/terrain/11/695/1234.png
## Source : http://tile.stamen.com/terrain/11/686/1235.png
## Source : http://tile.stamen.com/terrain/11/687/1235.png
## Source : http://tile.stamen.com/terrain/11/688/1235.png
## Source : http://tile.stamen.com/terrain/11/689/1235.png
## Source : http://tile.stamen.com/terrain/11/690/1235.png
## Source : http://tile.stamen.com/terrain/11/691/1235.png
## Source : http://tile.stamen.com/terrain/11/692/1235.png
## Source : http://tile.stamen.com/terrain/11/693/1235.png
## Source : http://tile.stamen.com/terrain/11/694/1235.png
## Source : http://tile.stamen.com/terrain/11/695/1235.png
## Source : http://tile.stamen.com/terrain/11/686/1236.png
## Source : http://tile.stamen.com/terrain/11/687/1236.png
## Source : http://tile.stamen.com/terrain/11/688/1236.png
## Source : http://tile.stamen.com/terrain/11/689/1236.png
## Source : http://tile.stamen.com/terrain/11/690/1236.png
## Source : http://tile.stamen.com/terrain/11/691/1236.png
## Source : http://tile.stamen.com/terrain/11/692/1236.png
## Source : http://tile.stamen.com/terrain/11/693/1236.png
## Source : http://tile.stamen.com/terrain/11/694/1236.png
## Source : http://tile.stamen.com/terrain/11/695/1236.png
## Source : http://tile.stamen.com/terrain/11/686/1237.png
## Source : http://tile.stamen.com/terrain/11/687/1237.png
## Source : http://tile.stamen.com/terrain/11/688/1237.png
## Source : http://tile.stamen.com/terrain/11/689/1237.png
## Source : http://tile.stamen.com/terrain/11/690/1237.png
## Source : http://tile.stamen.com/terrain/11/691/1237.png
## Source : http://tile.stamen.com/terrain/11/692/1237.png
## Source : http://tile.stamen.com/terrain/11/693/1237.png
## Source : http://tile.stamen.com/terrain/11/694/1237.png
## Source : http://tile.stamen.com/terrain/11/695/1237.png
## Source : http://tile.stamen.com/terrain/11/686/1238.png
## Source : http://tile.stamen.com/terrain/11/687/1238.png
## Source : http://tile.stamen.com/terrain/11/688/1238.png
## Source : http://tile.stamen.com/terrain/11/689/1238.png
## Source : http://tile.stamen.com/terrain/11/690/1238.png
## Source : http://tile.stamen.com/terrain/11/691/1238.png
## Source : http://tile.stamen.com/terrain/11/692/1238.png
## Source : http://tile.stamen.com/terrain/11/693/1238.png
## Source : http://tile.stamen.com/terrain/11/694/1238.png
## Source : http://tile.stamen.com/terrain/11/695/1238.png
Creamos mapa base para la localización de los tweets.
ggmap(mimapa)
mimapa_rmba <- get_stamenmap(bbox, maptype = "toner-lite", zoom = 11)
## 100 tiles needed, this may take a while (try a smaller zoom).
## Source : http://tile.stamen.com/toner-lite/11/686/1229.png
## Source : http://tile.stamen.com/toner-lite/11/687/1229.png
## Source : http://tile.stamen.com/toner-lite/11/688/1229.png
## Source : http://tile.stamen.com/toner-lite/11/689/1229.png
## Source : http://tile.stamen.com/toner-lite/11/690/1229.png
## Source : http://tile.stamen.com/toner-lite/11/691/1229.png
## Source : http://tile.stamen.com/toner-lite/11/692/1229.png
## Source : http://tile.stamen.com/toner-lite/11/693/1229.png
## Source : http://tile.stamen.com/toner-lite/11/694/1229.png
## Source : http://tile.stamen.com/toner-lite/11/695/1229.png
## Source : http://tile.stamen.com/toner-lite/11/686/1230.png
## Source : http://tile.stamen.com/toner-lite/11/687/1230.png
## Source : http://tile.stamen.com/toner-lite/11/688/1230.png
## Source : http://tile.stamen.com/toner-lite/11/689/1230.png
## Source : http://tile.stamen.com/toner-lite/11/690/1230.png
## Source : http://tile.stamen.com/toner-lite/11/691/1230.png
## Source : http://tile.stamen.com/toner-lite/11/692/1230.png
## Source : http://tile.stamen.com/toner-lite/11/693/1230.png
## Source : http://tile.stamen.com/toner-lite/11/694/1230.png
## Source : http://tile.stamen.com/toner-lite/11/695/1230.png
## Source : http://tile.stamen.com/toner-lite/11/686/1231.png
## Source : http://tile.stamen.com/toner-lite/11/687/1231.png
## Source : http://tile.stamen.com/toner-lite/11/688/1231.png
## Source : http://tile.stamen.com/toner-lite/11/689/1231.png
## Source : http://tile.stamen.com/toner-lite/11/690/1231.png
## Source : http://tile.stamen.com/toner-lite/11/691/1231.png
## Source : http://tile.stamen.com/toner-lite/11/692/1231.png
## Source : http://tile.stamen.com/toner-lite/11/693/1231.png
## Source : http://tile.stamen.com/toner-lite/11/694/1231.png
## Source : http://tile.stamen.com/toner-lite/11/695/1231.png
## Source : http://tile.stamen.com/toner-lite/11/686/1232.png
## Source : http://tile.stamen.com/toner-lite/11/687/1232.png
## Source : http://tile.stamen.com/toner-lite/11/688/1232.png
## Source : http://tile.stamen.com/toner-lite/11/689/1232.png
## Source : http://tile.stamen.com/toner-lite/11/690/1232.png
## Source : http://tile.stamen.com/toner-lite/11/691/1232.png
## Source : http://tile.stamen.com/toner-lite/11/692/1232.png
## Source : http://tile.stamen.com/toner-lite/11/693/1232.png
## Source : http://tile.stamen.com/toner-lite/11/694/1232.png
## Source : http://tile.stamen.com/toner-lite/11/695/1232.png
## Source : http://tile.stamen.com/toner-lite/11/686/1233.png
## Source : http://tile.stamen.com/toner-lite/11/687/1233.png
## Source : http://tile.stamen.com/toner-lite/11/688/1233.png
## Source : http://tile.stamen.com/toner-lite/11/689/1233.png
## Source : http://tile.stamen.com/toner-lite/11/690/1233.png
## Source : http://tile.stamen.com/toner-lite/11/691/1233.png
## Source : http://tile.stamen.com/toner-lite/11/692/1233.png
## Source : http://tile.stamen.com/toner-lite/11/693/1233.png
## Source : http://tile.stamen.com/toner-lite/11/694/1233.png
## Source : http://tile.stamen.com/toner-lite/11/695/1233.png
## Source : http://tile.stamen.com/toner-lite/11/686/1234.png
## Source : http://tile.stamen.com/toner-lite/11/687/1234.png
## Source : http://tile.stamen.com/toner-lite/11/688/1234.png
## Source : http://tile.stamen.com/toner-lite/11/689/1234.png
## Source : http://tile.stamen.com/toner-lite/11/690/1234.png
## Source : http://tile.stamen.com/toner-lite/11/691/1234.png
## Source : http://tile.stamen.com/toner-lite/11/692/1234.png
## Source : http://tile.stamen.com/toner-lite/11/693/1234.png
## Source : http://tile.stamen.com/toner-lite/11/694/1234.png
## Source : http://tile.stamen.com/toner-lite/11/695/1234.png
## Source : http://tile.stamen.com/toner-lite/11/686/1235.png
## Source : http://tile.stamen.com/toner-lite/11/687/1235.png
## Source : http://tile.stamen.com/toner-lite/11/688/1235.png
## Source : http://tile.stamen.com/toner-lite/11/689/1235.png
## Source : http://tile.stamen.com/toner-lite/11/690/1235.png
## Source : http://tile.stamen.com/toner-lite/11/691/1235.png
## Source : http://tile.stamen.com/toner-lite/11/692/1235.png
## Source : http://tile.stamen.com/toner-lite/11/693/1235.png
## Source : http://tile.stamen.com/toner-lite/11/694/1235.png
## Source : http://tile.stamen.com/toner-lite/11/695/1235.png
## Source : http://tile.stamen.com/toner-lite/11/686/1236.png
## Source : http://tile.stamen.com/toner-lite/11/687/1236.png
## Source : http://tile.stamen.com/toner-lite/11/688/1236.png
## Source : http://tile.stamen.com/toner-lite/11/689/1236.png
## Source : http://tile.stamen.com/toner-lite/11/690/1236.png
## Source : http://tile.stamen.com/toner-lite/11/691/1236.png
## Source : http://tile.stamen.com/toner-lite/11/692/1236.png
## Source : http://tile.stamen.com/toner-lite/11/693/1236.png
## Source : http://tile.stamen.com/toner-lite/11/694/1236.png
## Source : http://tile.stamen.com/toner-lite/11/695/1236.png
## Source : http://tile.stamen.com/toner-lite/11/686/1237.png
## Source : http://tile.stamen.com/toner-lite/11/687/1237.png
## Source : http://tile.stamen.com/toner-lite/11/688/1237.png
## Source : http://tile.stamen.com/toner-lite/11/689/1237.png
## Source : http://tile.stamen.com/toner-lite/11/690/1237.png
## Source : http://tile.stamen.com/toner-lite/11/691/1237.png
## Source : http://tile.stamen.com/toner-lite/11/692/1237.png
## Source : http://tile.stamen.com/toner-lite/11/693/1237.png
## Source : http://tile.stamen.com/toner-lite/11/694/1237.png
## Source : http://tile.stamen.com/toner-lite/11/695/1237.png
## Source : http://tile.stamen.com/toner-lite/11/686/1238.png
## Source : http://tile.stamen.com/toner-lite/11/687/1238.png
## Source : http://tile.stamen.com/toner-lite/11/688/1238.png
## Source : http://tile.stamen.com/toner-lite/11/689/1238.png
## Source : http://tile.stamen.com/toner-lite/11/690/1238.png
## Source : http://tile.stamen.com/toner-lite/11/691/1238.png
## Source : http://tile.stamen.com/toner-lite/11/692/1238.png
## Source : http://tile.stamen.com/toner-lite/11/693/1238.png
## Source : http://tile.stamen.com/toner-lite/11/694/1238.png
## Source : http://tile.stamen.com/toner-lite/11/695/1238.png
Utilizamos como base el mapa de “toner-lite” para una mejor visualización
ggmap(mimapa_rmba)
ggmap(mimapa_rmba) +
geom_point(data = tweets_rmba, aes(x = X, y = Y))
En este grafico podemos detectar la localización de los tweets realizados, detectando que la mayor concentración de los mismos se aloja en la Ciudad Autonoma de Buenos Aires.
tweets_rmba <- arrange(tweets_rmba, user_followers)
ggmap(mimapa_rmba) +
geom_point(data = tweets_rmba,
aes(x = X, y = Y, color = user_followers)) +
scale_color_distiller(palette = "Spectral")
Para una mejor visualización, en este grafico (que contiene la misma información que el anterior) diferenciamos los tweets por color, según la cantidad de seguidores que posee el usuario generador de los mismos.
I. Utilizar los tweets que descargaron en el ejercicio anterior o elegir algún dataset open data de la Ciudad que tenga tanto coordenadas como fecha. Quienes se animen pueden trabajar con ambos y luego compararlos entre sí.
Realizar 2 gráficos que les permitan analizar la temporalidad de los datos.¿Detectan algún patrón temporal? ¿A qué puede deberse?
Analizar la distribución espacial de los datos a partir de:
Cargamos dataset de sistema unico de atención ciudadana
sistema.unico.de.atencion.ciudadana.2020 <- read.csv("C:/Users/Maria/Downloads/ciencia de datos/sistema-unico-de-atencion-ciudadana-2020.csv", encoding = "UTF-8")
sistema.unico.de.atencion.ciudadana.2020 %>%
ggplot() +
geom_bar(aes(x = month(fecha_ingreso, label = TRUE)))
Podemos ver que el mes con mas consultas ha sido el mes de Enero.
Analizamos cuales han sido las consultas más frecuentes según categoría
sistema.unico.de.atencion.ciudadana.2020 %>%
count(categoria) %>%
top_n(5) %>%
arrange(desc(n))
## Selecting by n
## # A tibble: 5 x 2
## categoria n
## <chr> <int>
## 1 "" 118269
## 2 "TRÁNSITO" 45536
## 3 "LIMPIEZA Y RECOLECCIÓN" 18377
## 4 "CALLES Y VEREDAS" 14252
## 5 "ARBOLADO Y ESPACIOS VERDES" 13798
consultas_frecuentes <- sistema.unico.de.atencion.ciudadana.2020 %>%
filter(categoria != "", !is.na(categoria)) %>%
count(categoria) %>%
top_n(5) %>%
pull(categoria)
## Selecting by n
Realizamos un grafico para determinar cantidad de consultas frecuentes en los meses analizados.
sistema.unico.de.atencion.ciudadana.2020 %>%
filter(year(fecha_ingreso) == 2020,
categoria %in% consultas_frecuentes) %>%
ggplot() +
geom_bar(aes(x = month(fecha_ingreso, label = TRUE), fill = categoria))
Realizamos un conteo lineal según consultas frecuentes diferenciado por categorias
conteo <- sistema.unico.de.atencion.ciudadana.2020 %>%
filter(categoria %in% consultas_frecuentes) %>%
count(categoria, mes = month(fecha_ingreso, label = TRUE))
ggplot(conteo) +
geom_line(aes(x = mes, y = n, group = categoria, color = categoria))
ggmap(mimapa) +
geom_bin2d(data = sistema.unico.de.atencion.ciudadana.2020,
aes(x = long, y = lat))
## Warning: Removed 10661 rows containing non-finite values (stat_bin2d).
En el grafico podemos observar la cantidad de consultas realizadas en CABA
ggmap(mimapa) +
geom_bin2d(data = sistema.unico.de.atencion.ciudadana.2020, aes(x = long, y = lat), bins = 100) +
scale_fill_viridis_c()
## Warning: Removed 10661 rows containing non-finite values (stat_bin2d).
Este gráfico con colores permite diferenciar el barrio que presenta mayores consultas
ggmap(mimapa) +
geom_point(data = filter(sistema.unico.de.atencion.ciudadana.2020, categoria %in% consultas_frecuentes),
aes(x = long, y = lat, color = categoria),
size = 0.1, alpha = 0.1) +
guides(color = guide_legend(override.aes = list(size=2, alpha = 1))) +
scale_color_brewer(palette = "Set1")
En el grafico se puede observar las consultas localizadas y diferenciadas según el tipo de consulta
ggmap(mimapa) +
geom_point(data = filter(sistema.unico.de.atencion.ciudadana.2020, categoria %in% consultas_frecuentes),
aes(x = long, y = lat, color = categoria),
size = 0.1, alpha = 0.1) +
scale_color_brewer(palette = "Set1") +
facet_wrap(~categoria)
El grafico facetado permite mostrar cada categoría en su propio mapa
Realizamos la comparación de consultas de dos categorías diferentes para observar donde ocurren en cada dia de la semana
sistema.unico.de.atencion.ciudadana.2020 <- sistema.unico.de.atencion.ciudadana.2020 %>%
mutate(dia_semana = wday(fecha_ingreso, label = TRUE))
ggmap(mimapa) +
geom_point(data = filter(sistema.unico.de.atencion.ciudadana.2020,
categoria %in% c("ARBOLADO Y ESPACIOS VERDES", "CALLES Y VEREDAS")),
aes(x = long, y = lat, color = categoria), alpha = .5, size = .2) +
facet_wrap(~dia_semana)
I. Elegir UNA SOLA de las siguientes opciones: a. Un dataset que contenga viajes origen-destino (por ejemplo bicicletas públicas) de la Ciudad con la que están trabajando. b. Un dataset que contenga servicios esenciales (hospitales, escuelas, comisarías, etc) de la Ciudad con la que están trabajando. En este caso deberán elegir un barrio céntrico y uno periférico del shape de barrios y calcular ambos centroides. Los datos pueden ser descargados del portal open data de la ciudad o de OSM y deben tener ubicación geográfica.
Para entregar el ejercicio deberán publicarlo y compartir el link tal como hicieron en los ejercicios anteriores.
Cargamos librerias
library("osrm")
## Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright
## Routing: OSRM - http://project-osrm.org/
Elejimos dataset el dataset de Escuelas en CABA Y elegimos los barrios de Recoleta y Liniers y calcularemos sus centroides
establecimientos_educativos <- read_csv("~/ciencia de datos/establecimientos-educativos.csv")
## Parsed with column specification:
## cols(
## .default = col_character(),
## long = col_double(),
## lat = col_double(),
## objectid = col_double(),
## cui = col_double(),
## cueanexo = col_double(),
## cue = col_double(),
## anexo = col_double(),
## sector = col_double(),
## de = col_double(),
## calle_altura = col_double(),
## comunas = col_double(),
## codigo_postal = col_double(),
## estado = col_double(),
## point_x = col_double(),
## point_y = col_double()
## )
## See spec(...) for full column specifications.
barrios_centroides <- barrios %>%
st_centroid()
## Warning in st_centroid.sf(.): st_centroid assumes attributes are constant over
## geometries of x
## Warning in st_centroid.sfc(st_geometry(x), of_largest_polygon =
## of_largest_polygon): st_centroid does not give correct centroids for longitude/
## latitude data
ggplot()+
geom_sf(data=barrios, fill="pink")+
geom_sf(data=barrios_centroides, size=2)+
labs(title = "Barrios de la Ciudad",
subtitle = "Ubicación de los centroides",
fill="Barrios",
caption= "Fuente:https://data.buenosaires.gob.ar/")+
theme_void()
Tomamos como barrio periférico a Liniers y como céntrico a Recoleta
barrios_centroides <- barrios_centroides %>%
filter(barrio=="RECOLETA" | barrio=="LINIERS") %>%
mutate(ubicacion=if_else(barrio=="RECOLETA", "CENTRO", "PERIFERIA"))
Generamos los puntos x e y del centroide
barrios_centroides <- cbind(barrios_centroides, st_coordinates(barrios_centroides)) %>%
st_set_geometry(NULL)
Generamos el mapa de ubicación de centroides y establecimientos educativos
ggplot()+
geom_sf(data=barrios, fill="pink")+
geom_point(data=barrios_centroides, aes(x=X, y=Y, color=ubicacion), size=8)+
geom_point(data=establecimientos_educativos, aes(x=long, y=lat), color="blue")+
labs(title = "Barrios de la Ciudad",
subtitle = "Ubicación de los centroides",
color="Barrios",
caption= "Fuente:https://data.buenosaires.gob.ar/")+
theme_void()
A continuación prcedemos a estimar la distancia entre los centroides calculados en el punto I y los ítems que componen la capa descargada. Describir los resultados obtenidos y hacer los siguientes mapas
ruteo_establecimientos <- function(o_nombre, o_x, o_y, d_nombre, d_x, d_y) {
ruta <- osrmRoute(src = c(o_nombre, o_x, o_y),
dst = c(d_nombre, d_x, d_y),
returnclass = "sf",
overview = "full")
cbind(ORIGEN = o_nombre, DESTINO = d_nombre, ruta)
}
Hacemos ruteos del centroide del barrio céntrico a los establecimientos
establecimientos_recoleta <- establecimientos_educativos %>%
mutate(ORIGEN="RECOLETA") %>%
left_join(barrios_centroides, by=c("ORIGEN"="barrio")) %>%
rename(NOMBRE_ORIGEN=ORIGEN,
LONG_ORIGEN=X,
LAT_ORIGEN=Y,
NOMBRE_DESTINO=nombre_estab,
LONG_DESTINO=long,
LAT_DESTINO=lat) %>%
select(NOMBRE_ORIGEN, LONG_ORIGEN, LAT_ORIGEN, NOMBRE_DESTINO, LONG_DESTINO, LAT_DESTINO)
ruteo_recoleta <- list(establecimientos_recoleta$NOMBRE_ORIGEN, establecimientos_recoleta$LONG_ORIGEN,establecimientos_recoleta$LAT_ORIGEN,
establecimientos_recoleta$NOMBRE_DESTINO, establecimientos_recoleta$LONG_DESTINO,establecimientos_recoleta$LAT_DESTINO)
ruteo_centrico <- pmap(ruteo_recoleta, ruteo_establecimientos) %>%
reduce(rbind)
ruteo_centrico <-mutate(ruteo_centrico, RUTA = paste(ORIGEN,"a", DESTINO))
filter(ruteo_centrico, distance == min(distance))
## Simple feature collection with 1 feature and 7 fields
## geometry type: LINESTRING
## dimension: XY
## bbox: xmin: -58.39756 ymin: -34.58714 xmax: -58.39503 ymax: -34.58484
## geographic CRS: WGS 84
## ORIGEN DESTINO src
## 1 RECOLETA Escuela Nacional de Bibliotecarios RECOLETA
## dst duration distance
## 1 Escuela Nacional de Bibliotecarios 4.195 0.6259
## geometry RUTA
## 1 LINESTRING (-58.39503 -34.5... RECOLETA a Escuela Nacional de Bibliotecarios
El establecimiento educativo mas cercano a Recoleta es la Escuela Nacional de Bibliotecarios a 0,6 km con una duracion aproximada de 4 min de viaje
leaflet(ruteo_centrico) %>%
addTiles() %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
addPolylines(color = ~colorNumeric("BrBG", ruteo_centrico$distance)(distance),
label = ruteo_centrico$RUTA %>%
lapply(htmltools::HTML)) %>%
addLegend("bottomright", pal = colorNumeric("BrBG", ruteo_centrico$distance), values = ~distance,
title = "Distancia",
opacity = 0.55)