Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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

1 ACCEPTED SOLUTION
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 🙂

View solution in original post

3 REPLIES 3
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 🙂

v-cherch-msft
Employee
Employee

Hi @Anonymous

 

You may have a look at below post for reference.

 

https://community.powerbi.com/t5/R-Script-Showcase/Map-with-connecting-lines/td-p/80294

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.