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 / magritt

 

The main problem that I have is that the script in PowerBI doesn't draw both points, but in R-Studio works fine.

 

Images:

https://ibb.co/cN8VWz
https://ibb.co/e9Phde
https://ibb.co/jSJm4K

 

R code of R visual:

library(maps)
library(geosphere)
library(magrittr)

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))

OrigenDataset <-dataset [c(1,2,3,4)]
DestinoDataset <-dataset [c(5,6,7,8)]

O.Lat <- OrigenDataset$O.Latitude
O.Lon <- OrigenDataset$O.Longitude

D.Lat <- DestinoDataset$D.Latitude
D.Lon <- DestinoDataset$D.Longitude

OrigenPunto <- c(O.Lon,O.Lat)
DestinoPunto <- c(D.Lon,D.Lat)

p1 <- c(O.Lon,D.Lon)
p2 <- c(O.Lat,D.Lat)

points(x=p1, y=p2, col="#96ce00", cex=2, pch=20)

# Connection between Barcelona, Madrid
#inter <- gcIntermediate(OrigenPunto, DestinoPunto, n=50, addStartEnd=TRUE, breakAtDateLine=F)             
#lines(inter, col="#96ce00", lwd=2)

Pbix file: https://drive.google.com/open?id=1pZNdJRleudTBXXG9LT4II26GOJWxS0Jc

Airports file: https://drive.google.com/open?id=1KuktzNZ_2eatqLFwfHV9C_7MOwTqN0RG

 

The final purpose is to draw a line between the two airports.

 

Please... help.

 

Thanks :-)

Luis

  • 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 :-)

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    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 :-)

    • Anonymous's avatar
      Anonymous
      Not applicable

      It's not the same case. Australia's data is on the same dataframe-table, but my map needs as source two different tables... :-/

       

      Thank you anyway :-)