01 | Tarea: Unir Datos Espaciales
ACLARACIONES - Luego del mapa deberán agregar conclusiones acerca de lo que ven en los resultados. - Se recomienda agregar etiquetas (títulos, subtítulos, etc) en todos los mapas y cuando sea posible y resulte útil, realizar facetados.
FORMATO DE ENTREGA El ejercicio se debe realizar en formato RMarkdown pero en este curso no hará falta que envíen el HTML resultante, ya que alcanza con el link de rpubs tras haberlo publicado desde RStudio (instructivo adjunto).
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.0 v dplyr 1.0.5
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sf)
## Warning: package 'sf' was built under R version 4.0.5
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
data_properati <- read.csv("ar_properties.csv")
caba_comunas <- st_read("CABA_comunas.geojson")
## Reading layer `comunas' from data source `C:\Users\pablo\Google Drive\Personal\Estudios\UTDT\2. Segundo\02. Segundo Trimestre\Ciencia de Datos para Ciudades II\Trabajo Final\CABA_comunas.geojson' using driver `GeoJSON'
## Simple feature collection with 15 features and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -58.53152 ymin: -34.70529 xmax: -58.33515 ymax: -34.52649
## Geodetic CRS: WGS 84
caba_barrios <- st_read("barrios.geojson")
## Reading layer `barrios_badata' from data source `C:\Users\pablo\Google Drive\Personal\Estudios\UTDT\2. Segundo\02. Segundo Trimestre\Ciencia de Datos para Ciudades II\Trabajo Final\barrios.geojson' using driver `GeoJSON'
## Simple feature collection with 48 features and 4 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -58.53152 ymin: -34.70529 xmax: -58.33515 ymax: -34.52649
## Geodetic CRS: WGS 84
caba_radios <- st_read("caba_radios_censales.geojson")
## Reading layer `CABA_rc' from data source `C:\Users\pablo\Google Drive\Personal\Estudios\UTDT\2. Segundo\02. Segundo Trimestre\Ciencia de Datos para Ciudades II\Trabajo Final\caba_radios_censales.geojson' using driver `GeoJSON'
## Simple feature collection with 3554 features and 8 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -58.53092 ymin: -34.70574 xmax: -58.33455 ymax: -34.528
## Geodetic CRS: WGS 84
caba_hospitales <- st_read("hospitales.geojson")
## Reading layer `hospitales_gcba_WGS84' from data source `C:\Users\pablo\Google Drive\Personal\Estudios\UTDT\2. Segundo\02. Segundo Trimestre\Ciencia de Datos para Ciudades II\Trabajo Final\hospitales.geojson' using driver `GeoJSON'
## Simple feature collection with 36 features and 19 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -58.51563 ymin: -34.67185 xmax: -58.36012 ymax: -34.5539
## Geodetic CRS: WGS 84
caba_barrios <- st_transform(caba_barrios, 4326)
caba_comunas <- st_transform(caba_comunas, 4326)
caba_hospitales <- st_transform(caba_hospitales, 4326)
caba_radios <- st_transform(caba_radios, 4326)
summary(data_properati)
## id ad_type start_date end_date
## Length:1000000 Length:1000000 Length:1000000 Length:1000000
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## created_on lat lon l1
## Length:1000000 Min. :-54.84 Min. :-122.54 Length:1000000
## Class :character 1st Qu.:-34.79 1st Qu.: -58.79 Class :character
## Mode :character Median :-34.60 Median : -58.47 Mode :character
## Mean :-34.60 Mean : -59.34
## 3rd Qu.:-34.44 3rd Qu.: -58.38
## Max. : 49.23 Max. : 58.70
## NA's :128195 NA's :128570
## l2 l3 l4 l5
## Length:1000000 Length:1000000 Length:1000000 Length:1000000
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## l6 rooms bedrooms bathrooms
## Mode:logical Min. : 1.0 Min. : -2.0 Min. : 1.00
## NA's:1000000 1st Qu.: 2.0 1st Qu.: 1.0 1st Qu.: 1.00
## Median : 3.0 Median : 2.0 Median : 1.00
## Mean : 2.9 Mean : 2.1 Mean : 1.72
## 3rd Qu.: 4.0 3rd Qu.: 3.0 3rd Qu.: 2.00
## Max. :40.0 Max. :900.0 Max. :20.00
## NA's :363401 NA's :421235 NA's :231506
## surface_total surface_covered price currency
## Min. : -136.0 Min. : -130 Min. :0.000e+00 Length:1000000
## 1st Qu.: 50.0 1st Qu.: 45 1st Qu.:4.000e+04 Class :character
## Median : 95.0 Median : 78 Median :9.800e+04 Mode :character
## Mean : 504.1 Mean : 7284 Mean :3.258e+05
## 3rd Qu.: 250.0 3rd Qu.: 170 3rd Qu.:2.100e+05
## Max. :200000.0 Max. :2147483647 Max. :3.100e+09
## NA's :582426 NA's :575557 NA's :41014
## price_period title description property_type
## Length:1000000 Length:1000000 Length:1000000 Length:1000000
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## operation_type
## Length:1000000
## Class :character
## Mode :character
##
##
##
##
data_properati <- filter(data_properati, l2 == "Capital Federal")
data_properati <- filter(data_properati, !lat == "NA")
data_properati <- filter(data_properati, !lon == "NA")
data_properati <- filter(data_properati, !price == "NA")
summary(data_properati)
## id ad_type start_date end_date
## Length:210498 Length:210498 Length:210498 Length:210498
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## created_on lat lon l1
## Length:210498 Min. :-53.79 Min. :-100.470 Length:210498
## Class :character 1st Qu.:-34.61 1st Qu.: -58.459 Class :character
## Mode :character Median :-34.60 Median : -58.432 Mode :character
## Mean :-34.59 Mean : -58.449
## 3rd Qu.:-34.58 3rd Qu.: -58.402
## Max. : 38.05 Max. : -5.491
##
## l2 l3 l4 l5
## Length:210498 Length:210498 Length:210498 Length:210498
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## l6 rooms bedrooms bathrooms
## Mode:logical Min. : 1.00 Min. : -2.00 Min. : 1.000
## NA's:210498 1st Qu.: 2.00 1st Qu.: 1.00 1st Qu.: 1.000
## Median : 2.00 Median : 2.00 Median : 1.000
## Mean : 2.58 Mean : 1.88 Mean : 1.536
## 3rd Qu.: 3.00 3rd Qu.: 2.00 3rd Qu.: 2.000
## Max. :40.00 Max. :156.00 Max. :20.000
## NA's :41196 NA's :71834 NA's :27396
## surface_total surface_covered price currency
## Min. : 10.0 Min. : -130.0 Min. : 0 Length:210498
## 1st Qu.: 43.0 1st Qu.: 40.0 1st Qu.: 42900 Class :character
## Median : 67.0 Median : 60.0 Median : 115000 Mode :character
## Mean : 159.6 Mean : 158.3 Mean : 230396
## 3rd Qu.: 124.0 3rd Qu.: 105.0 3rd Qu.: 218000
## Max. :140380.0 Max. :950000.0 Max. :111000000
## NA's :60688 NA's :63156
## price_period title description property_type
## Length:210498 Length:210498 Length:210498 Length:210498
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## operation_type
## Length:210498
## Class :character
## Mode :character
##
##
##
##
data_properati_geo <- data_properati %>%
st_as_sf(coords=c("lon","lat"), crs=4326)
ggplot()+
geom_sf(data=data_properati_geo, color="blue")+
labs(title="Departamentos en Venta CABA 2020",
subtitle = "Fuente: Properati Data")
Vemos que a pesar de filtrar propiedades por “Capital Federal” no logramos un mapa correcto.
data_properati_geo <- st_join(data_properati_geo, 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
data_properati_geo <- filter(data_properati_geo, !is.na(barrio))
ggplot()+
geom_sf(data=caba_barrios)+
geom_sf(data=data_properati_geo, color="blue", alpha = 0.5)+
labs(title="Publicaciones CABA",
subtitle = "Fuente: Properati Data")
Conclusiones:luego de realizar el join espacial con barrios pudimos filtrar y quedarnos unicamente con las publicaciones que caen en CABA
3.1. Un gráfico (barras, puntos, o el que prefieran) para mostrar los resultados de cantidad por barrio.
ggplot(data = data_properati_geo) + geom_bar(aes(y = barrio, fill = barrio))+
labs(title="Cantidad de Publicaciones por Barrio",
subtitle = "Fuente: Properati Data",
y="Cantidad de Propiedades",
x="Barrio")
Conclusiones: encontramos la mayor cantidad de publicaciones en el Barrrio de Palermo, seguido por Recoleta, y en tercer lugar Belgrano casi empatado con Villa Crespo que está en 4to lugar
3.2. Un mapa coroplético con los límites de los barrios, cuyo color de relleno indique la cantidad encontrada en cada uno.
cantxbarrio <- data_properati_geo %>%
st_set_geometry(NULL) %>%
group_by(barrio) %>%
summarise(cantidad=n())
caba_barrios <- left_join(caba_barrios, cantxbarrio, by = "barrio")
ggplot()+
geom_sf(data=caba_barrios, aes(fill=cantidad)) +
geom_sf_label(data=caba_barrios, aes(label = barrio), size=4) +
scale_fill_distiller(palette = "Spectral") +
theme_light()+
labs(title="Cantidad de publicaciones de departamentos por Barrio",
subtitle = "Fuente: Properati Data")
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data
Conclusiones: Luego de construir el dataset con la cantidad de publicaciones por barrio, y haciendo el join con el dataset original de barrios, creamos el mapa coroplético de cantidad de publicaciones por barrio, confirmando que la mayor cantidad se concentra en Palermo, Recoleta y Belgrano.