Refs:
# download from http://cran.r-project.org/web/packages/rworldmap/index.html
# and high def map from http://cran.r-project.org/web/packages/rworldxtra/index.html
library(rworldmap)
## Loading required package: sp
## ### Welcome to rworldmap ###
## For a short introduction type : vignette('rworldmap')
newmap <- getMap(resolution = "low")
plot(newmap)
library(ggmap)
## Loading required package: ggplot2
europe.limits <- geocode(c(
"CapeFligely,RudolfIsland,Franz Josef Land,Russia",
"Gavdos,Greece",
"Faja Grande,Azores",
"SevernyIsland,Novaya Zemlya,Russia")
)
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=CapeFligely,RudolfIsland,Franz+Josef+Land,Russia&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Gavdos,Greece&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Faja+Grande,Azores&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=SevernyIsland,Novaya+Zemlya,Russia&sensor=false
europe.limits
## lon lat
## 1 60.64878 80.58823
## 2 24.08464 34.83469
## 3 -31.26192 39.45479
## 4 56.00000 74.00000
plot(newmap,
xlim = range(europe.limits$lon),
ylim = range(europe.limits$lat),
asp = 1.0
)
Get some data, in this case a dataset including airport coordinates:
# from http://openflights.org/data.html
airports <- read.csv("airports.dat", header = FALSE)
colnames(airports) <- c("ID", "name", "city", "country", "IATA_FAA", "ICAO", "lat", "lon", "altitude", "timezone", "DST")
head(airports)
## ID name city country IATA_FAA
## 1 1 Goroka Goroka Papua New Guinea GKA
## 2 2 Madang Madang Papua New Guinea MAG
## 3 3 Mount Hagen Mount Hagen Papua New Guinea HGU
## 4 4 Nadzab Nadzab Papua New Guinea LAE
## 5 5 Port Moresby Jacksons Intl Port Moresby Papua New Guinea POM
## 6 6 Wewak Intl Wewak Papua New Guinea WWK
## ICAO lat lon altitude timezone DST NA
## 1 AYGA -6.081689 145.3919 5282 10 U Pacific/Port_Moresby
## 2 AYMD -5.207083 145.7887 20 10 U Pacific/Port_Moresby
## 3 AYMH -5.826789 144.2959 5388 10 U Pacific/Port_Moresby
## 4 AYNZ -6.569828 146.7262 239 10 U Pacific/Port_Moresby
## 5 AYPY -9.443383 147.2200 146 10 U Pacific/Port_Moresby
## 6 AYWK -3.583828 143.6692 19 10 U Pacific/Port_Moresby
Now place them in the map
plot(newmap, xlim = range(europe.limits$lon), ylim = range(europe.limits$lat), asp = 1.0)
points(airports$lon, airports$lat, col = "red", cex = .25)
Get a map from Google Maps (there’s also other servers)
library(ggmap)
library(mapproj)
## Loading required package: maps
map <- get_map(location = 'Europe', zoom = 4)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Europe&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Europe&sensor=false
ggmap(map)