Search code examples
rleafletr-leaflet

R leaflet.minicharts change addflows direction on map


I have a leaflet map in R, and am using the leaflet.minicharts function addFlows to show direction of product from origin to destination. This causes some confusion on the links from China to the United States. Leaflet defaults to showing the lines going from east to west, instead of from west to east, across the Pacific Ocean. Is there any way to change the direction the China --> United States lines are plotted?

enter image description here


Solution

  • Answering my own question, for future searchers.

    For longitudes < 0 degrees (Western Hemisphere), add 360 degrees. This makes China --> US flows go over the International Date Line.

    Note that you need to do this for both the leaflet.minicharts::addFlows lng0 and lng1, and the longitude of any markers/circlemarkers.

    Referencing accepted answer at How to display Leaflet markers near the 180° meridian?