I am trying to build with ggplot2 a bird track around Antarctica. As long as I have a map projected in polar coordinates, I also managed to plot the points on the track correctly, and I connect them almost correctly, but ...
When a track crosses an international date line (i.e. 180 ° longitude), ggplot2 cannot correctly connect 2 points on either side of the line. He connects them, but, having gone all the way on the earth. So Iām looking for a way to get ggplot to connect the points along the shortest path 180 °.
Here is my code and the resulting graph.
require(ggplot2) require(rgdal)
Data:
track<-read.table("NOGP_87470_track.txt", sep="\t",h=T)
consists of 75 reference points characterized by longitude / latitude / date (POSIXct). PTT is the name of the bird. The date here is useless.
head(track) :
PTT long lat date 1 87470 51.645 -46.334 2009-02-03 14:50:00 2 87470 52.000 -46.289 2009-02-04 20:11:00 3 87470 52.556 -46.083 2009-02-06 07:15:00 4 87470 55.822 -44.667 2009-02-07 17:28:00 5 87470 60.679 -41.915 2009-02-09 04:03:00 6 87470 63.059 -41.649 2009-02-10 15:04:00
Here is the piece of data where the track crosses the line (line: 19 and 20)
PTT long lat date 18 87470 160.907 -53.356 2009-02-28 06:25:00 19 87470 165.791 -54.588 2009-03-01 15:39:00 20 87470 -174.636 -50.893 2009-03-03 05:04:00 21 87470 -160.111 -50.832 2009-03-04 13:47:00 22 87470 -138.875 -53.474 2009-03-06 01:49:00
map (shapefile of world coastlines in Cartesian coordinates)
world<-readOGR("Coastlines\\World_continental_WGS84_Proj.shp", "World_continental_WGS84_Proj")
plot
p <- ggplot(track, aes(x=long, y=lat)) p <- p + geom_polygon( data=world, aes(x=long, y=lat, group = group),colour="grey", fill="gainsboro" ) + theme( panel.grid.major.x = element_blank()) + coord_polar(theta="x", start=pi/2,direction=1) + # project the map in polar coordinates ylim (-90, -20) # to keep only south hemisphere pp <- p + geom_point(size=3,shape=19) + geom_path(size=1,col="grey")
And here is what I get:
red arrows - this is the direction of flight of the bird:

I green 2 points that I want to connect along the 180 ° line, and manually made a green dotted line between them. As you can see, they are connected by a line that goes around the pole in the wrong direction.
Has anyone got an idea on how to deal with this?