0

I am trying to add great circle routes between various regions in R. Here's the sample data:

structure(list(CommencingRegion = c("RedSea", "EastAfrica", "GulfofMexico", 
"FarEast", "RedSea", "GulfofMexico"), LoadRegion = c("RedSea", 
"RedSea", "GulfofMexico", "FarEast", "RedSea", "GulfofMexico"
), DischargeRegion = c("NorthWestAfrica", "WestMedditerranean", 
"WestCoastLatinAmerica", "AustraliaNewZealand", "WestMedditerranean", 
"WestCoastCentralAmerica"), Count = c(1L, 1L, 2L, 1L, 2L, 5L), 
    AvgTCE = c(38879.53, 31783.55, 28520.79, 26068.8, 26054.28, 
    25883.81), CLon = c(37.8274879335485, 47.0791103099334, -90.9633701509553, 
    146.2727573458, 37.8274879335485, -90.9633701509553), CLat = c(21.4460561443517, 
    -12.9570828789565, 25.2035802054683, 47.6530892619773, 21.4460561443517, 
    25.2035802054683), LLon = c(37.8274879335485, 37.8274879335485, 
    -90.9633701509553, 146.2727573458, 37.8274879335485, -90.9633701509553
    ), LLat = c(21.4460561443517, 21.4460561443517, 25.2035802054683, 
    47.6530892619773, 21.4460561443517, 25.2035802054683), DLon = c(-17.1597117430475, 
    7.03639948506481, -73.4238157230412, 151.051220297802, 7.03639948506481, 
    255.83509305644), DLat = c(24.2308740597312, 38.8907379374372, 
    -25.8934046406896, -25.1880219406131, 38.8907379374372, 21.8130318388702
    )), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))

I would like to plot great circle routes between CommencingRegion to LoadingRegion and then from LoadingRegion to DischargeRegion for every row. Additionally, every row needs to be in a different color and the thickness needs to be proportional to AvgTCE. The last 6 variables in the data above are the coordinates in Lat Long for the commencing, loading and discharging regions respectively. I am quite clueless on how to go about achieving this. This is what I have tried and failed:

leaflet() %>% 
  addTiles() %>% 
  for(i in 1:6){
    addPolylines(data=gcIntermediate(c(ByRoute$CLon[i],ByRoute$CLat[i]),c(ByRoute$LLon[i],ByRoute$CLat[i]),n=100,addStartEnd = T,sp=T))
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.