ejecutar el siguiente código si no se dispone del paquete ggmap: devtools::install_github(“dkahle/ggmap”)
ejecutar el siguiente código si al ejecutar los comandos aparecen errores relacionados con el environment: devtools::install_github("hadley/ggplot2@v2.2.0")
library(ggmap)
## Loading required package: ggplot2
## Google Maps API Terms of Service: http://developers.google.com/maps/terms.
## Please cite ggmap if you use it: see citation("ggmap") for details.
setwd("~/Desktop/Taller")
Viviendas <- read.csv("listings.csv")
Hay tres formas de seleccionar la zona a visualizar
Madrid=c(-3.6883432,40.453054)
map.Madrid <- get_map(location = Madrid)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.453054,-3.688343&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN
ggmap(map.Madrid)
Barcelona <- geocode("Barcelona",source = "google")
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Barcelona
map.Barcelona <- get_map(location = Barcelona)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=41.385064,2.173404&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN
ggmap(map.Barcelona)
PeninsulaIberica <- c(left=-12,bottom=34,right=4,top=44.5)
map.PeninsulaIberica <- get_map(PeninsulaIberica)
## Warning: bounding box given to google - spatial extent only approximate.
## converting bounding box to center/zoom specification. (experimental)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=39.25,-4&zoom=6&size=640x640&scale=2&maptype=terrain&language=en-EN
ggmap(map.PeninsulaIberica)
EJERCICIO: Visualizar un mapa de Nueva York
NuevaYork <- geocode("Nueva York",source = "google")
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=Nueva%20York
map.NuevaYork <- get_map(location = NuevaYork)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.712784,-74.005941&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN
ggmap(map.NuevaYork)
el maptype por defecto es “terrain”
map.PeninsulaIberica1 <- get_map(PeninsulaIberica, maptype = "satellite")
## Warning: bounding box given to google - spatial extent only approximate.
## converting bounding box to center/zoom specification. (experimental)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=39.25,-4&zoom=6&size=640x640&scale=2&maptype=satellite&language=en-EN
ggmap(map.PeninsulaIberica1)
map.PeninsulaIberica <- get_map(PeninsulaIberica, maptype = "hybrid")
## Warning: bounding box given to google - spatial extent only approximate.
## converting bounding box to center/zoom specification. (experimental)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=39.25,-4&zoom=6&size=640x640&scale=2&maptype=hybrid&language=en-EN
ggmap(map.PeninsulaIberica)
map.PeninsulaIberica3 <- get_map(PeninsulaIberica, maptype = "roadmap")
## Warning: bounding box given to google - spatial extent only approximate.
## converting bounding box to center/zoom specification. (experimental)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=39.25,-4&zoom=6&size=640x640&scale=2&maptype=roadmap&language=en-EN
ggmap(map.PeninsulaIberica3)
map.PeninsulaIberica <- get_map(PeninsulaIberica, maptype = "watercolor")
## maptype = "watercolor" is only available with source = "stamen".
## resetting to source = "stamen"...
## Source : http://tile.stamen.com/watercolor/6/29/23.jpg
## Source : http://tile.stamen.com/watercolor/6/30/23.jpg
## Source : http://tile.stamen.com/watercolor/6/31/23.jpg
## Source : http://tile.stamen.com/watercolor/6/32/23.jpg
## Source : http://tile.stamen.com/watercolor/6/29/24.jpg
## Source : http://tile.stamen.com/watercolor/6/30/24.jpg
## Source : http://tile.stamen.com/watercolor/6/31/24.jpg
## Source : http://tile.stamen.com/watercolor/6/32/24.jpg
## Source : http://tile.stamen.com/watercolor/6/29/25.jpg
## Source : http://tile.stamen.com/watercolor/6/30/25.jpg
## Source : http://tile.stamen.com/watercolor/6/31/25.jpg
## Source : http://tile.stamen.com/watercolor/6/32/25.jpg
ggmap(map.PeninsulaIberica)
EJERCICIO: Visualizar un mapa de Nueva York tipo satellite
map.NuevaYork <- get_map(NuevaYork, maptype = "satellite")
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.712784,-74.005941&zoom=10&size=640x640&scale=2&maptype=satellite&language=en-EN
ggmap(map.NuevaYork)
Bernabeu=c(-3.6883432,40.453054)
map.Bernabeu <- get_map(location = Bernabeu,zoom = 17,maptype = "satellite")
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.453054,-3.688343&zoom=17&size=640x640&scale=2&maptype=satellite&language=en-EN
ggmap(map.Bernabeu)
dev.off()
## null device
## 1
png("./mapa bernabeu.png")
ggmap(map.Bernabeu)
dev.off()
## null device
## 1
ArtedeMedir <- geocode("El Arte de Medir, Calle Cundinamarca, Madrid",source = "google")
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=El%20Arte%20de%20Medir%2C%20Calle%20Cundinamarca%2C%20Madrid
map.ArtedeMedir <- get_map(location = as.numeric(ArtedeMedir),zoom = 20,maptype = "satellite")
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.470838,-3.631555&zoom=20&size=640x640&scale=2&maptype=satellite&language=en-EN
ggmap(map.ArtedeMedir)
dev.off()
## null device
## 1
png("./mapa elartedemedir.png")
ggmap(map.ArtedeMedir)
dev.off()
## null device
## 1
NuevaYork <- geocode("NuevaYork",source = "google")
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=NuevaYork
map.NuevaYork<- get_map(location = as.numeric(NuevaYork),zoom = 14,maptype = "roadmap")
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.712784,-74.005941&zoom=14&size=640x640&scale=2&maptype=roadmap&language=en-EN
ggmap(map.NuevaYork)