library(ggplot2)
library(ggmap)
# You should get your own api key from Google. Follow: https://cloud.google.com/maps-platform/
register_google(apiKey)
# Quick plot of the City of Cali / Google Maps provider
qmap("Cali", zoom = 10)
# get_googlemap() can access Google Static Maps API and customize the map attributes. See:
# https://developers.google.com/maps/documentation/static-maps/
qmap("Cali", zoom = 10, maptype = "hybrid")
# The same map from a different map provider. See: http://maps.stamen.com/
qmap("Cali", zoom = 10, source = "stamen", maptype = "toner")
#Load a map
city <- get_map("Cali", zoom = 15)
# With that data and the long/lat of the center you can get the ggplot2 object used by ggmap to plot the raster image on top.
str(city)
## 'ggmap' chr [1:1280, 1:1280] "#A8A7A6" "#A8A7A6" "#A8A7A6" "#A8A7A6" ...
## - attr(*, "source")= chr "google"
## - attr(*, "maptype")= chr "terrain"
## - attr(*, "zoom")= num 15
## - attr(*, "bb")=Classes 'tbl_df', 'tbl' and 'data.frame': 1 obs. of 4 variables:
## ..$ ll.lat: num 3.44
## ..$ ll.lon: num -76.5
## ..$ ur.lat: num 3.47
## ..$ ur.lon: num -76.5
# Generate the map
caliMap <- ggmap(city)
# Get data from file
MIO_STOPS<- read.delim(file="MIO_STOPS.txt")
MIO_STOPS$PASSANGERS_NUM<-MIO_STOPS$PASSANGERS_NUM/10
# Add points to the map
caliMap <- caliMap + geom_point(data = MIO_STOPS, aes(x= DECIMALLONGITUDE, y = DECIMALLATITUDE), color = "red", alpha = 1)
# Plot the map
caliMap
# Cali coords
CaliCoords <- geocode("Chipichape,Cali")
# Retrieve the map fron the provider
cityCenter <- get_map(c(CaliCoords$lon, CaliCoords$lat), source= "stamen", maptype="toner", zoom = 16)
# Generate the map
caliCenter <- ggmap(cityCenter)
# Add points to the map
caliCenter <- caliCenter + geom_point(aes(x= DECIMALLONGITUDE, y = DECIMALLATITUDE),data = MIO_STOPS, color = "red")
# Plot the map
caliCenter
El ejercicio es buscar mi ubicación buscando en Google maps la dirección de mi casa. se realiza un mapa centrado sobre mi casa y se dibuja los paraderos del Mio mas cercanos. El diámetro de los puntos debe representar el número de pasajeros y el color el tipo de bus.
# Cali coords
CaliCoords <- geocode("3.3699644,-76.5161393")
# Retrieve the map fron the provider
cityCenter <- get_map(c(CaliCoords$lon, CaliCoords$lat), source= "stamen", maptype="toner", zoom = 16)
# Generate the map
caliCenter <- ggmap(cityCenter)
# Add points to the map
caliCenter <- caliCenter + geom_point(aes(x= DECIMALLONGITUDE, y = DECIMALLATITUDE),data = MIO_STOPS, color = "red")
# Plot the map
caliCenter