From Barcelona to Boston in R

Today I am traveling to Boston to attend the BioC 2017: Where Software and Biology Connect. In this trip to Boston, I stop in Lisbon to take the transoceanic flight.

Let’s see a map Boston-Barcelona “centered” using the package maps:

library( maps )

xlim <- c( -140, 20 )
ylim <- c(   25, 50 )
map( "world", lwd = 0.75, xlim = xlim, ylim = ylim )

Using ggmap we can get the longitude and the latitude of the cities:

library(ggmap)

gp <- geocode(c("Barcelona", "Lisboa", "Boston"))

Having the global map, and the geo-positions of Barcelona, Lisbon and Boston, a map with the flights I am taking can be drawn using geosphere function gcIntermediate to accurate draw the connections:

library(geosphere)

map("world", lwd=0.75,  xlim=xlim, ylim=ylim)
for(ii in 2:nrow(gp)) {
    inter <- gcIntermediate(
        p1 = c( gp$lon[ ii - 1 ], gp$lat[ ii - 1] ), 
        p2 = c( gp$lon[ ii ], gp$lat[ ii ] ), 
        n = 50, 
        addStartEnd = TRUE
    )
    lines(inter, col = "red")
}