I'm creating a visualization from country centroids to a few thousand coordinate pairs, and I'd like them to all be displayed unbroken and smooth on the same map, but I get these horizontal lines when passing the international date line at the edges. I'm using a modified version of this nycflights13 visual. My error is the same as this GIS Stack Exchange user's error, but using R.
My code is below:
library(maps)
library(geosphere)
df <- data.frame(
Lat_pt = c(24.30515,23.86345,23.39825,24.17565,23.09845,21.46860),
Lon_pt = c(85.14140,89.73296,81.40266,88.11363,85.85935,90.96883),
Lat_centroid = 45.67626,
Lon_centroid = -112.4708)
maps::map("world", fill = T, col = "grey8", bg = "grey15")
points(df$Lon_pt,df$Lat_pt, pch=3, cex=0.1, col="chocolate1")
for (i in (1:dim(df)[1])) {
inter <- gcIntermediate(c(df$Lon_pt[i], df$Lat_pt[i]), c(df$Lon_centroid[i], df$Lat_centroid[i]), n=200)
lines(inter, lwd = 0.5, col="turquoise2")
}
Which generates this visual:
How can I force these paths that draw across the date line to instead draw only on the map, directly from centroid to point?
I believe my error results from my use of the geosphere package, documented here