Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

R visual · Draw connecting line between two points

Hello,   I need to create a map that shows the connection between two points (both airports).  Origin / Destination airport must be from different tables.   R libraries: maps / geosphere / magri...
  • Anonymous's avatar
    Anonymous
    7 years ago

    I have found the solution:

     

    library(maps)
    library(geosphere)
    library(magrittr)
    
    Punto1 <- c(dataset$O.Lon,dataset$O.Lat)
    Punto2 <- c(dataset$D.Lon,dataset$D.Lat)
    
    map("world", xlim=c(-10,5),ylim=c(35,44) ,col="#1a2732", bg="white", fill=TRUE, lty = 0, interior = false,mar = c(0.1, 0.1, 0, 0.1))
    
    points(x=dataset$O.Lon, y=dataset$O.Lat, col="#96ce00", cex=2, pch=20)
    points(x=dataset$D.Lon, y=dataset$D.Lat, col="#96ce00", cex=2, pch=20)
    
    inter <- gcIntermediate(Punto1, Punto2, n=50, addStartEnd=TRUE, breakAtDateLine=F)             
    lines(inter, col="#96ce00", lwd=2)

    The easiest one :-)