3

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

Niels
  • 141
  • 12
  • 1
    You will need coordinates of the cities then you can use `geom_point` to highlight them. `aes()` can take arguments `color`, `size`, and `alpha` which will help used adjust highlighting settings as you wish. You will need to `install.packages("ggplot")` for this to work – Abdallah Atef Apr 16 '19 at 22:31
  • Thanks for your suggestion, I added some data in the variable cities. How could geom_point be integrated in the code? – Niels Apr 17 '19 at 06:34

1 Answers1

1

The easiest way from here is going to be:

cities <- coordinates(cities)

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

However, if you need to modify your map at any point (for example to reproject/transform points) you would probably need to look into using vector geometries and sf/rgdal: https://r-spatial.github.io/sf/

Phil
  • 4,344
  • 2
  • 23
  • 33