#PAQUETES NECESARIOS

library(maptools)
## Warning: package 'maptools' was built under R version 3.6.3
## Loading required package: sp
## Checking rgeos availability: TRUE
library(ggmap)
## Loading required package: ggplot2
## 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(rgdal)
## rgdal: version: 1.4-8, (SVN revision 845)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
##  Path to GDAL shared files: C:/Users/Juan Ignacio/Documents/R/win-library/3.6/rgdal/gdal
##  GDAL binary built with GEOS: TRUE 
##  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
##  Path to PROJ.4 shared files: C:/Users/Juan Ignacio/Documents/R/win-library/3.6/rgdal/proj
##  Linking to sp version: 1.3-2
library(leaflet)
library(viridis)
## Loading required package: viridisLite
library(httr)
library(jsonlite)
library(htmltools)
library(sp)
library(sf)
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(mapview)
library(leafem)
## 
## Attaching package: 'leafem'
## The following objects are masked from 'package:mapview':
## 
##     addFeatures, addHomeButton, addImageQuery, addLogo,
##     addMouseCoordinates, garnishMap, removeHomeButton,
##     removeMouseCoordinates
library(reshape2)
library(ggplot2)
library(data.table)
## 
## Attaching package: 'data.table'
## The following objects are masked from 'package:reshape2':
## 
##     dcast, melt
library(tidyverse)
## -- Attaching packages -------------------------------------------------------------------------- tidyverse 1.3.0 --
## v tibble  2.1.3     v dplyr   0.8.4
## v tidyr   1.0.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## v purrr   0.3.3
## -- Conflicts ----------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::between()   masks data.table::between()
## x dplyr::filter()    masks stats::filter()
## x dplyr::first()     masks data.table::first()
## x purrr::flatten()   masks jsonlite::flatten()
## x dplyr::lag()       masks stats::lag()
## x dplyr::last()      masks data.table::last()
## x purrr::transpose() masks data.table::transpose()
library(gganimate)
library(gifski)
library(osmdata)
## Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
setwd("C:/Users/Juan Ignacio/Desktop/Datos/")
recorridos <- readOGR(dsn = ".", layer = "recorrido-colectivos")
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\Juan Ignacio\Desktop\Datos", layer: "recorrido-colectivos"
## with 2066 features
## It has 16 fields
## Integer64 fields read as strings:  shape_id direction_ route_id agency_id route_type service_id exceptiona
recotrenes <- readOGR(dsn = ".", layer = "red_ferrocarriles")
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\Juan Ignacio\Desktop\Datos", layer: "red_ferrocarriles"
## with 52 features
## It has 6 fields
## Integer64 fields read as strings:  id sentido
recosubtes <- readOGR(dsn = ".", layer = "lineas-subte")
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\Juan Ignacio\Desktop\Datos", layer: "lineas-subte"
## with 82 features
## It has 2 fields
## Integer64 fields read as strings:  ID
estasubtes <- read.csv("C:/Users/Juan Ignacio/Desktop/Datos/estaciones-de-subte.csv")
estatrenes<- read.csv("C:/Users/Juan Ignacio/Desktop/Datos/estaciones-de-ferrocarril.csv")
leaflet()%>% 
  addProviderTiles("CartoDB.Positron") %>%  # PARA TENER MAPA BACK, SI NO LO QUERES, BORRA ESTA LINEA
  addFeatures(recotrenes,color = "green",weight=4,label = recotrenes$geometry, opacity = 1) %>%
  addFeatures(recosubtes,color = "purple",weight=3,label = recosubtes$geometry, opacity = 1) %>%
  addFeatures(recorridos,color = "black",weight=1,label = recorridos$geometry, opacity = 1) %>%
  addCircles(estatrenes, weight = 8, lng = estatrenes$long, lat = estatrenes$lat, radius =5, color = "green") %>%
  addCircles(estasubtes, weight = 8, lng = estasubtes$long, lat = estasubtes$lat, radius = 5, color = "purple")