I am using greatCircle function to create a map. I am able to run the code and get the desired connecting lines across the locations. But additionally I am getting an arbitrary straight line in the middle of the map. I am not able to understand why it's happening. And how it can be dropped? I am pasting the picture and the code below. The data set I here use is in built data in the package "maps"
first I remove your code that truncates the circle, and just take the circle, then I plot for fewer location, but close to and including your problem which occurs at i = 5 and j = 17 ; conditionally colouring this as red to highlight it for you.
library("maps")
library("geosphere")
getGreatCircle <- function(userLL,relationLL){
greatC = greatCircle(userLL,relationLL, n=200)
# start = which.min(abs(tmpCircle[,1] - data.frame(userLL)[1,1]))
# end = which.min(abs(tmpCircle[,1] - relationLL[1]))
# greatC = tmpCircle[start:end,]
return(greatC)}
par(mar=c(0,0,0,0))
# World map
map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-80,80))
for(i in 4:5){for(j in 16:17){ if(i != j){
col <- "skyblue"
if(i==5 & j==17)
col <- "red"
inter<- getGreatCircle(c(world.cities$long[i],world.cities$lat[i]),c(world.cities$long[j],world.cities$lat[j]))
lines(inter, col=col, lwd=0.2)}}
}