Question

I need to visualize some geodata in a world map. I have learnt the Flowing Data's great circle mapping tutorial and the result seems odd. It is like the following:

The result is here

And apparently I need to avoid these crossing-picture lines. But how can I do that? The code to plot the map is this:

map("world", col="#f2f2f2", fill=TRUE, bg="white",lwd=0.05) 
for (j in 1:length(location$lon)) {
 inter <- gcIntermediate(c(lon_nj, lat_nj), c(location$lon[j], location$lat[j]),      n=100, addStartEnd=TRUE)
lines(inter, col="black", lwd=0.8)
}

And I have tried the code provided by gpe Automating great-circle map production in R

 map("world", col="#f2f2f2", fill=TRUE, bg="white",lwd=0.05) 
 for (j in 1:length(location$lon)) {
 inter <- clean.Inter(c(lon_nj, lat_nj), c(location$lon[j], location$lat[j]),n=100, addStartEnd=TRUE)
  lines(inter, col="black", lwd=0.8)
 }

And the result is like this: The inter-clear method

And I just want to use the shortest distance to get to the required place.

And the answers from web like using another function like greatCircle() has also failed to realize my goal.

So is there anyone have some idea how to realize this purpose?

Thank you very much!!

Was it helpful?

Solution

One option would be to switch to a map that is centered on the Pacific ocean and splits the Atlantic. This might be the easiest to view.

Another option would be to examine the inter object (probably a list with x and y, but I am not familiar with the exact functions used) and see if the x coordinates tend to increase or decrease. Look for the place where they suddenly jump the other direction and insert an NA there (and in the same place in the y values), then the lines crossing the entire plot will not be shown. If that does not work you could insert an NA anywhere that the distance between points exceeds a threshold.

Another quick idea that may be good enough (partly depends on how many points are used for each curve) is to plot points instead of lines, use points(inter, pch='.') instead of the lines command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top