mapdata パッケージから地図を描画します。投影されていないときに簡単にいくつかのポイントを追加できます。マップにメルカトル図法を使用したいのですが、ポイントも投影しようとしましたが、このマップに追加する方法が見つかりませんでした。多分私は正しい射影文字列を使用していませんか?それとも私は愚かな間違いを犯しましたか?
# points dataset with coordinates of some European cities
places <- structure(list(city = structure(c(3L, 12L, 1L, 2L, 9L, 5L, 11L,
15L, 7L, 13L, 4L, 16L, 10L, 14L, 8L, 6L, 17L), .Label = c("Amsterdam",
"Berlin", "Brussels", "Copenhagen", "Dublin", "Genève", "Helsinki",
"Lisboa", "London", "Madrid", "Oslo", "Paris", "Reykjavik", "Roma",
"Stockholm", "Warsaw", "Wien"), class = "factor"), lon = c(4.3517103,
2.3522219, 4.8951679, 13.4060912, -0.1198244, -6.2603097, 10.7522454,
18.06491, 24.9410248, -21.89521, 12.5683371, 21.0122287, -3.7037902,
12.4825199, -9.1500364, 6.1422961, 16.3738189), lat = c(50.8503396,
48.856614, 52.3702157, 52.519171, 51.5112139, 53.3498053, 59.9138688,
59.32893, 60.1733244, 64.135338, 55.6760968, 52.2296756, 40.4167754,
41.8929163, 38.7252993, 46.1983922, 48.2081743)), .Names = c("city",
"lon", "lat"), row.names = c(NA, -17L), class = "data.frame")
library(maps)
library(mapdata)
# simple map with long lat as plot coordinates
map(database = "worldHires", xlim=c(-12,50), ylim=c(35, 70), resolution = 1, mar=c(0,0,0,0))
points(places$lon, places$lat, col = "red")
# transform the points data.frame into a spatial object
library(sp)
coordinates(places) <- c("lon", "lat")
proj4string(places) <- CRS("+proj=longlat")
# this map works
map(database = "worldHires", xlim=c(-12,50), ylim=c(35, 70), resolution = 1, mar=c(0,0,0,0))
plot(places, add=TRUE, col = "red")
# project the points with Mercator projection (maybe not the wright one?)
library(rgdal)
places <- spTransform(places, CRS("+proj=merc"))
# The map with mercator projection is ok but the points are not there (and their
# coordinates values are indeed very different from the map coordinates)
map(database = "worldHires",projection = "mercator", xlim=c(-12,50), ylim=c(35, 70), resolution = 1, mar=c(0,0,0,0))
plot(places, add=TRUE, col = "red")