R-cards - how to draw lines between countries?

In R, using the map package and gcIntermediate, how to draw lines between two countries? It needs a lat-long, but I'm not sure what I should give to countries for a long time (say, I want to draw a line between the USA and the Swede)

+6
source share
1 answer

There are several cards that you can use, depending on what information / part / etc. you need, but for this a very nice wrld_simpl will work just fine:

 library(maptools) library(geosphere) data(wrld_simpl) US_lat = wrld_simpl$LAT[wrld_simpl$NAME == 'United States'] US_lon = wrld_simpl$LON[wrld_simpl$NAME == 'United States'] SWE_lat = wrld_simpl$LAT[wrld_simpl$NAME == 'Sweden'] SWE_lon = wrld_simpl$LON[wrld_simpl$NAME == 'Sweden'] points = gcIntermediate(c(US_lon, US_lat), c(SWE_lon, SWE_lat), 100) dev.new(width=6, height=4) plot(wrld_simpl) lines(points, col='red') 

enter image description here

+8
source

Source: https://habr.com/ru/post/903499/


All Articles