Refs

Draft version, still lots to explore

library(maptools)
## Loading required package: sp
## Checking rgeos availability: TRUE
uk <- readShapeSpatial("map.shp", proj4string=CRS("+proj=longlat"))
plot(uk)

summary(uk)
## Object of class SpatialPolygonsDataFrame
## Coordinates:
##         min       max
## x -13.69139  1.764168
## y  49.86542 60.845822
## Is projected: FALSE 
## proj4string : [+proj=longlat +ellps=WGS84]
## Data attributes:
##      MM_UID            CODE                  NAME1               NAME2    
##  Min.   :  1.00   GB.ED  :  2   England         :112   Aberdeen     :  1  
##  1st Qu.: 48.75   GB.AB  :  1   Northern Ireland: 26   Aberdeenshire:  1  
##  Median : 96.50   GB.AD  :  1   Scotland        : 32   Anglesey     :  1  
##  Mean   : 96.50   GB.AG  :  1   Wales           : 22   Angus        :  1  
##  3rd Qu.:144.25   GB.AM  :  1                          Antrim       :  1  
##  Max.   :192.00   GB.AN  :  1                          Ards         :  1  
##                   (Other):185                          (Other)      :186  
##          DIVISION  
##  Kingdom     :144  
##  Principality: 22  
##  Province    : 26  
##                    
##                    
##                    
## 
library(maps)

france<-map(database="france")

names(france)
## [1] "x"     "y"     "range" "names"
head(france$names)
## [1] "Nord"           "Pas-de-Calais"  "Somme"          "Nord:1"        
## [5] "Ardennes"       "Seine-Maritime"
library(mapdata)

map(database="worldHires", "Portugal") 

library(RgoogleMaps)

lat <- c(37,42) #define our map's ylim
lon <- c(-9,-6) #define our map's xlim
center = c(mean(lat), mean(lon))  #tell what point to center on
zoom <- 7  #zoom: 1 = furthest out (entire globe), larger numbers = closer in

terrmap <- GetMap(center=center, zoom=zoom, maptype= "terrain", destfile = "terrain.png") 
# lots of visual options, just like google maps: 
#   maptype = c("roadmap", "mobile", "satellite", "terrain", "hybrid", "mapmaker-roadmap", "mapmaker-hybrid")
PlotOnStaticMap(terrmap)

path = paste0("&path=color:0x0000ff|weight:3|",
              "38.7138,-9.14|39.12,-9.21|39.0,-8.5")
MyMap <- GetMap(center=center, zoom=zoom, path = path)
PlotOnStaticMap(MyMap)

library(ggmap)
## Loading required package: ggplot2
library(geosphere) # use: gcIntermediate

# this example shows obtaining coordinates (latitude, longitude) using
# map_world function, and drawing them using geom_polygon
world <- map_data("world")
basemap <- ggplot(legend = FALSE) + 
           geom_polygon(data = world, aes(x = long,  y = lat, group = group, fill = group)) + 
           theme(legend.position = "none")  

lx <- geocode("Lisbon, PT") # find coordinates
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Lisbon,+PT&sensor=false
ny <- geocode("New York, USA")
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=New+York,+USA&sensor=false
inter <- as.data.frame(gcIntermediate(c(lx$lon, lx$lat), c(ny$lon, ny$lat), n = 50, addStartEnd = TRUE))
basemap + geom_line(data = inter, aes(x = lon, y = lat), color = "red")

# using maps to plot routes
rt1 = route(from = "Lisbon", to = "Castelo Branco", mode = "driving")
## Information from URL : http://maps.googleapis.com/maps/api/directions/json?origin=Lisbon&destination=Castelo+Branco&mode=driving&units=metric&alternatives=false&sensor=false
PortugalMap <- qmap("Portugal", zoom = 8, color = "bw")
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Portugal&zoom=8&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Portugal&sensor=false
PortugalMap + geom_leg(aes(x = startLon, y = startLat, xend = endLon, yend = endLat),
                       color = "blue", data = rt1)