library("tidyverse")
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.2     v dplyr   1.0.7
## 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("ggplot2")
  library("shiny")
  library("sf")
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
  library("randomForest")
## randomForest 4.6-14
## Type rfNews() to see new features/changes/bug fixes.
## 
## Attaching package: 'randomForest'
## The following object is masked from 'package:dplyr':
## 
##     combine
## The following object is masked from 'package:ggplot2':
## 
##     margin
  library("osmdata")
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
  library("leaflet")
  library("sp")
  library("rgeos")
## rgeos version: 0.5-5, (SVN revision 640)
##  GEOS runtime version: 3.8.0-CAPI-1.13.1 
##  Linking to sp version: 1.4-5 
##  Polygon checking: TRUE
  library("maps")
## 
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
## 
##     map
  library("rmarkdown")
  library("treemap")
  library("lubridate")
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:rgeos':
## 
##     intersect, setdiff, union
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
  library("rgdal")
## rgdal: version: 1.5-23, (SVN revision 1121)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: C:/Users/sixto/OneDrive/Documentos/R/win-library/4.1/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/sixto/OneDrive/Documentos/R/win-library/4.1/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Overwritten PROJ_LIB was C:/Users/sixto/OneDrive/Documentos/R/win-library/4.1/rgdal/proj
  library("lwgeom")
## Linking to liblwgeom 3.0.0beta1 r16016, GEOS 3.9.0, PROJ 7.2.1
  library("readxl")
  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("htmltools")
  library("plotly")
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggmap':
## 
##     wind
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
  library("rgdal")
  library("haven")
## Warning: package 'haven' was built under R version 4.1.1
  library("mapview")
## Warning: package 'mapview' was built under R version 4.1.1
  library("hrbrthemes")
## Warning: package 'hrbrthemes' was built under R version 4.1.2
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
##       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
##       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
calles <-read_sf ("https://cdn.buenosaires.gob.ar/datosabiertos/datasets/jefatura-de-gabinete-de-ministros/calles/callejero.geojson")
avenidas = calles %>% filter(tipo_c =="AVENIDA")
radios = read_sf("https://cdn.buenosaires.gob.ar/datosabiertos/datasets/informacion-censal-por-radio/caba_radios_censales.geojson")
radios = radios %>% mutate (femeneidad = as.numeric(T_MUJER) /as.numeric(TOTAL_POB) )

Graficamos la femeneidad y las avenidas

ggplot() + 
    geom_sf(data = radios, aes(fill = femeneidad), color = NA) +
    scale_fill_viridis_c() +
    labs(title = "Femenización de los radios censales",
         subtitle = "Ciudad Autónoma de Buenos Aires",
         fill = "% de poblacion femenina por radio censal") + geom_sf(data= avenidas)

Calculamos la distancia de los radios censales a las avenidas

start.time <- Sys.time()
radios = radios %>%   mutate(dist_avenida = apply(st_distance(radios, avenidas), 1, function(x) min(x)))
radios = radios %>% filter( femeneidad >0.3)
end.time <- Sys.time()
time.taken <- end.time - start.time
time.taken
## Time difference of 6.425079 mins
p3 <- ggplot(radios, aes(y=radios$femeneidad, x=radios$dist_avenida)) +
  geom_point() +
  geom_smooth(method=lm , color="red", fill="#69b3a2", se=TRUE) +
  theme_ipsum()
cor(x =radios$femeneidad, y= radios$dist_avenida)
## [1] -0.02011164
subtes =  read_sf("https://cdn.buenosaires.gob.ar/datosabiertos/datasets/sbase/subte-estaciones/subte_estaciones.geojson")
radios = radios %>% mutate(dist_subte = apply(st_distance(radios, subtes), 1, function(x) min(x)))
p4 <- ggplot(radios, aes(y=radios$femeneidad, x=radios$dist_subte)) +
  geom_point() +
  geom_smooth(method=lm , color="red", fill="#69b3a2", se=TRUE) +
  theme_ipsum()
cor(radios$femeneidad,radios$dist_subte)
## [1] -0.2040477
ggplot() + 
    geom_sf(data = radios, aes(fill = femeneidad), color = NA) +
    scale_fill_viridis_c() +
    labs(title = "Femenización de los radios censales",
         subtitle = "Ciudad Autónoma de Buenos Aires",
         fill = "% de poblacion femenina por radio censal") + geom_sf(data= subtes)

ggplot() + 
    geom_sf(data = radios, aes(fill = dist_subte), color = NA) +
    scale_fill_viridis_c() +
    labs(title = "Femenización de los radios censales",
         subtitle = "Ciudad Autónoma de Buenos Aires",
         fill = "Distancia a una estacion de subterráneo") + geom_sf(data= subtes)

radios_cerca = radios %>% filter(dist_subte >500)
radios_lejos = radios %>% filter(dist_subte <500)

summary(radios_lejos$femeneidad)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.3530  0.5333  0.5501  0.5481  0.5660  0.6667
summary(radios_cerca$femeneidad)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.3200  0.5196  0.5345  0.5348  0.5502  0.6223