ejerccio a realizar I a. Un dataset que contenga viajes origen-destino (por ejemplo bicicletas públicas) de la Ciudad con la que están trabajando.
recorridos.realizados.2018.xls. <- read.csv("~/R 2020/Deber 10 analizar y visualizar rutas/recorridos-realizados-2018 xls..csv")
head(recorridos.realizados.2018.xls.)
## id_usuario genero_usuario fecha_origen_recorrido id_estacion_origen
## 1 5453 M 1/1/2018 0:08 45
## 2 673 M 1/1/2018 0:18 189
## 3 179119 F 1/1/2018 0:20 50
## 4 400147 M 1/1/2018 0:20 111
## 5 400156 F 1/1/2018 0:20 111
## 6 476733 F 1/1/2018 0:21 121
## nombre_estacion_origen long_estacion_origen lat_estacion_origen
## 1 Uruguay -58.38691 -34.60162
## 2 Posadas -58.38559 -34.58847
## 3 Hospital Rivadavia -58.40115 -34.58368
## 4 Macacha Güemes -58.36300 -34.60497
## 5 Macacha Güemes -58.36300 -34.60497
## 6 Yatay -58.42827 -34.60082
## domicilio_estacion_origen duracion_recorrido
## 1 Tucumán y Uruguay 0 days 00:19:53.000000000
## 2 Posadas 1350 entre Montevideo y RodrÃguez Peña 0 days 00:26:19.000000000
## 3 Lucena Pereyra 2516 entre Las Heras y Pagano 0 days 00:27:39.000000000
## 4 Macacha Guemes y Juana Manso 0 days 00:48:51.000000000
## 5 Macacha Guemes y Juana Manso 0 days 00:49:27.000000000
## 6 Yatay 925 entre Humahuaca y Guardia Vieja 0 days 00:36:10.000000000
## fecha_destino_recorrido id_estacion_destino nombre_estacion_destino
## 1 1/1/2018 0:27 183 Virrey Cevallos
## 2 1/1/2018 0:44 110 Guardia Vieja
## 3 1/1/2018 0:47 31 Padilla
## 4 1/1/2018 1:09 54 Acuña de Figueroa
## 5 1/1/2018 1:09 54 Acuña de Figueroa
## 6 1/1/2018 0:57 143 Billinghurst y ValentÃn Gomez
## long_estacion_destino lat_estacion_destino
## 1 -58.38969 -34.61564
## 2 -58.41546 -34.60176
## 3 -58.43971 -34.60316
## 4 -58.42170 -34.59822
## 5 -58.42170 -34.59822
## 6 -58.41576 -34.60464
## domicilio_estacion_destino
## 1 México 1652 entre Virrey Cevallos y SolÃs
## 2 Guardia Vieja 3606 entre Billinghurst y Mario Bravo
## 3 Padilla y Warnes Av
## 4 Lavalle y Acuña de Figueroa
## 5 Lavalle y Acuña de Figueroa
## 6 Billinghurst 455 y ValentÃn Gomez
names(recorridos.realizados.2018.xls.)
## [1] "id_usuario" "genero_usuario"
## [3] "fecha_origen_recorrido" "id_estacion_origen"
## [5] "nombre_estacion_origen" "long_estacion_origen"
## [7] "lat_estacion_origen" "domicilio_estacion_origen"
## [9] "duracion_recorrido" "fecha_destino_recorrido"
## [11] "id_estacion_destino" "nombre_estacion_destino"
## [13] "long_estacion_destino" "lat_estacion_destino"
## [15] "domicilio_estacion_destino"
summary(recorridos.realizados.2018.xls.)
## id_usuario genero_usuario fecha_origen_recorrido id_estacion_origen
## Min. : 8 F:289399 6/19/2018 18:05: 42 Min. : 1.00
## 1st Qu.:139654 M:759175 5/3/2018 18:07 : 39 1st Qu.: 39.00
## Median :323312 N: 1 6/28/2018 18:10: 39 Median : 91.00
## Mean :299743 6/25/2018 17:04: 38 Mean : 94.73
## 3rd Qu.:453196 6/14/2018 18:06: 36 3rd Qu.:147.00
## Max. :571040 6/19/2018 18:22: 36 Max. :200.00
## (Other) :1048345 NA's :12281
## nombre_estacion_origen long_estacion_origen lat_estacion_origen
## PacÃfico : 15860 Min. :-58.45 Min. :-34.64
## Parque Las Heras : 14487 1st Qu.:-58.42 1st Qu.:-34.61
## Facultad de Medicina: 14111 Median :-58.40 Median :-34.60
## Plaza Italia : 14078 Mean :-58.40 Mean :-34.60
## Parque Centenario : 12355 3rd Qu.:-58.38 3rd Qu.:-34.59
## Retiro III : 12162 Max. :-58.36 Max. :-34.57
## (Other) :965522 NA's :12281 NA's :12281
## domicilio_estacion_origen
## PacÃfico : 15860
## Plaza Fuerza Aérea: Av. Dr. J. Ramos Mejia y Av Del Libertador: 15007
## Parque Las Heras : 14487
## Uriburu y Marcelo T. de Alvear : 14111
## Av. Santa Fe y Av. Sarmiento : 14078
## Patricias Argentinas y Carlos Finlay : 12355
## (Other) :962677
## duracion_recorrido fecha_destino_recorrido
## : 19529 : 19529
## 0 days 00:09:29.000000000: 913 6/6/2018 18:45 : 38
## 0 days 00:11:03.000000000: 902 5/3/2018 18:21 : 34
## 0 days 00:09:00.000000000: 898 6/19/2018 18:14: 34
## 0 days 00:09:28.000000000: 897 5/22/2018 8:59 : 33
## 0 days 00:09:56.000000000: 897 6/25/2018 17:48: 33
## (Other) :1024539 (Other) :1028874
## id_estacion_destino nombre_estacion_destino long_estacion_destino
## Min. : 1.00 PacÃfico : 15535 Min. :-58.45
## 1st Qu.: 40.00 Facultad de Medicina: 14123 1st Qu.:-58.42
## Median : 92.00 Parque Las Heras : 13531 Median :-58.40
## Mean : 95.23 Parque Centenario : 12221 Mean :-58.40
## 3rd Qu.:147.00 Plaza Italia : 11905 3rd Qu.:-58.38
## Max. :200.00 Facultad de Derecho : 11067 Max. :-58.36
## NA's :12366 (Other) :970193 NA's :12366
## lat_estacion_destino
## Min. :-34.64
## 1st Qu.:-34.62
## Median :-34.60
## Mean :-34.60
## 3rd Qu.:-34.59
## Max. :-34.57
## NA's :12366
## domicilio_estacion_destino
## PacÃfico : 15535
## Uriburu y Marcelo T. de Alvear : 14123
## Parque Las Heras : 13531
## Plaza Fuerza Aérea: Av. Dr. J. Ramos Mejia y Av Del Libertador: 12895
## : 12366
## Patricias Argentinas y Carlos Finlay : 12221
## (Other) :967904
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.6.3
## -- Attaching packages ------------------------------------------------------ tidyverse 1.3.0 --
## v ggplot2 3.3.0 v purrr 0.3.3
## v tibble 2.1.3 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
## Warning: package 'ggplot2' was built under R version 3.6.3
## Warning: package 'tibble' was built under R version 3.6.2
## Warning: package 'tidyr' was built under R version 3.6.3
## Warning: package 'readr' was built under R version 3.6.3
## Warning: package 'purrr' was built under R version 3.6.3
## Warning: package 'dplyr' was built under R version 3.6.3
## Warning: package 'stringr' was built under R version 3.6.3
## Warning: package 'forcats' was built under R version 3.6.3
## -- Conflicts --------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggmap)
## Warning: package 'ggmap' was built under R version 3.6.3
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
bbox <- make_bbox(recorridos.realizados.2018.xls.$long_estacion_origen,recorridos.realizados.2018.xls.$lat_estacion_origen)
caba <- get_stamenmap(bbox, zoom=12)
## Source : http://tile.stamen.com/terrain/12/1382/2467.png
## Source : http://tile.stamen.com/terrain/12/1383/2467.png
## Source : http://tile.stamen.com/terrain/12/1384/2467.png
## Source : http://tile.stamen.com/terrain/12/1382/2468.png
## Source : http://tile.stamen.com/terrain/12/1383/2468.png
## Source : http://tile.stamen.com/terrain/12/1384/2468.png
ggmap(caba) +
labs(title= "Sector de CABA donde estan las estaciones de Bicicletas,2018 ")
bbox1 <- make_bbox(recorridos.realizados.2018.xls.$long_estacion_destino,recorridos.realizados.2018.xls.$lat_estacion_destino)
caba <- get_stamenmap(bbox,zoom=12)
ggmap(caba) +
geom_point (data = recorridos.realizados.2018.xls., aes(x = long_estacion_origen, y = lat_estacion_origen), color = "red")+
labs(tittle= "Estaciones de origen en CABA BICI ",
subtitle = "Estaciones de Bici-CABA 2018",
caption = "Caba.gob")
## Warning: Removed 12281 rows containing missing values (geom_point).
caba <- get_stamenmap(bbox,zoom=12)
ggmap(caba) +
geom_point (data = recorridos.realizados.2018.xls., aes(x = long_estacion_destino, y = lat_estacion_destino), color = "blue")
## Warning: Removed 12366 rows containing missing values (geom_point).
origen <- select(recorridos.realizados.2018.xls.,id_estacion_origen,nombre_estacion_origen)
origen %>%
count(id_estacion_origen) %>%
arrange(desc(n))
## # A tibble: 197 x 2
## id_estacion_origen n
## <int> <int>
## 1 14 15860
## 2 9 14487
## 3 33 14111
## 4 5 14078
## 5 29 12355
## 6 NA 12281
## 7 131 12162
## 8 1 11546
## 9 160 10827
## 10 8 10774
## # ... with 187 more rows
destino <- select(recorridos.realizados.2018.xls.,id_estacion_destino)
destino %>%
count (id_estacion_destino) %>%
arrange (desc(n))
## # A tibble: 197 x 2
## id_estacion_destino n
## <int> <int>
## 1 14 15535
## 2 33 14123
## 3 9 13531
## 4 NA 12366
## 5 29 12221
## 6 5 11905
## 7 1 11067
## 8 8 10910
## 9 131 10803
## 10 160 10677
## # ... with 187 more rows
origen_destino <-select(recorridos.realizados.2018.xls.,id_estacion_origen,nombre_estacion_origen,id_estacion_destino,long_estacion_origen,lat_estacion_origen,long_estacion_destino,lat_estacion_destino,nombre_estacion_destino,duracion_recorrido)
heatmap <-origen_destino %>%
count(id_estacion_origen,id_estacion_destino)%>%
filter(!is.na(id_estacion_origen),!is.na(id_estacion_destino))%>%
arrange(desc(n))
heatmap10<- heatmap %>%
top_n(10)
## Selecting by n
head(heatmap10)
## # A tibble: 6 x 3
## id_estacion_origen id_estacion_destino n
## <int> <int> <int>
## 1 14 14 2365
## 2 152 152 2188
## 3 5 5 2146
## 4 29 29 1983
## 5 160 160 1770
## 6 26 26 1623
ggplot()+
geom_tile(data= heatmap10,
aes (x=as.factor(id_estacion_origen),
y= as.factor(id_estacion_destino),
fill= n)) +
labs(title = " Recorridos Ida y vuelta de ECO BICI CABA 2018 ",
subtitle = "Heatmap",
caption = "CABA.gob")+
scale_fill_distiller(palette = "Spectral")