Simple world map with highlighted countries and selected cities

时间:2019-04-16 22:18:58

标签: r ggplot2 city maptools rworldmap

I would like to draw a world map and to highlight selected countries and cities. The countries and cities will present locations where study data were obtained. Unfortunately, I was able to do this. I could only highlight the countries. How could I add cities as it is shown in magenta, and ultimately the name of the cities or countries?

library(maptools)
data(wrld_simpl)

lat<-c(7,13.3,12,46,38,52.31)
lon<-c(6,16,105,2,23.7,13.23)
cities<-data.frame(lat,lon)
myCountries = wrld_simpl@data$NAME %in% c("Australia",  "Germany",  "Sweden", "Austria")
plot(wrld_simpl, col = c(gray(.90), "red")[myCountries+1])

enter image description here

1 个答案:

答案 0 :(得分:0)

从这里开始最简单的方法是:

cities <- coordinates(cities)

plot(wrld_simpl, col = c(gray(.90), "red")[myCountries+1])
points(cities, col = "purple", lwd = 7)

但是,如果您需要在任意点修改地图(例如重新投影/变换点),则可能需要研究使用矢量几何和sf / rgdal:{{3 }}