title: Overlay multiple riverplots (Sankey diagrams) on a map of the world
body: <p>The fascinating chart below is in the <em>Economist</em>, Jan. 30, 2016 at 61.  It depicts exports of liquified natural gas (LNG) from five regions to six regions.  How can R draw something similar to it, perhaps with several Sankey diagrams (from the package <code>riverplots</code>) but with arrows reversed as the depicted arrow heads?  Meaning, the flows into the exporting region would show as flowing out.</p>
  
  <p><a href="https://i.stack.imgur.com/mpeoM.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mpeoM.png" alt="Economist map with flows"></a></p>
  
  <p>Extracting the data from the plot by eyeball resulted in the df data frame.  The variables have strange names because the `riverplot requires unique node names.</p>
  
  <pre><code>&gt; dput(df)
  structure(list(ID = structure(c(1L, 6L, 9L, 13L, 2L, 7L, 14L, 
  3L, 10L, 15L, 4L, 11L, 5L, 8L, 12L, 16L), .Label = c("Africa-Asia", 
  "Africa-Europe", "Africa-Nam", "Africa-SE", "Africa-SthAm", "Europe-Asia", 
  "Europe-Europe", "Europe-SthAm", "MidEast-Asia", "MidEast-NthAm", 
  "MidEast-SE", "MidEast-SthAm", "SE Asia-Asia", "Sth Am.-Eur", 
  "Sth Am.-NthAm", "Sth Am.-SthAm"), class = "factor"), x = c(-30, 
  1, 20, 100, -30, 1, -100, -30, 20, -100, -30, 20, -30, 1, 20, 
  -100), y = c(120, 120, 120, 120, 1, 1, 1, -120, -120, -120, 100, 
  100, -100, -100, -100, -100), value = c(21, 22, 290, 100, 22, 
  3, 16, 1, 5, 6, 2, 62, 3, 3, 5, 3), col = structure(c(2L, 3L, 
  5L, 1L, 2L, 3L, 4L, 2L, 5L, 4L, 2L, 5L, 2L, 3L, 5L, 4L), .Label = c("brickred", 
  "green", "purple", "red", "yellow"), class = "factor"), region = structure(1:16, .Label = c("Asia-Africa", 
  "Asia-Eur", "Asia-ME", "Asia-SE", "Europe-Africa", "Europe-Eur", 
  "Europe-SthAm", "No. Am.-Africa", "No. Am.-ME", "No. Am.-Stham", 
  "SE Asia-Afr", "SE Asia-MI", "Sth. Am.-Africa", "Sth. Am.-Eur", 
  "Sth. Am.-ME", "Sth. Am.-SthAm"), class = "factor")), .Names = c("ID", 
  "x", "y", "value", "col", "region"), row.names = c(NA, -16L), class = "data.frame")
  </code></pre>
  
  <p>Creating the map is straightforward (although it would look better with Antarctica melted!).  Tru, the goal is not a choropleth -- with colored regions according to some variable -- but Ari Lamstein's package <code>choroplethr</code> and its complement, <code>choroplethrMaps</code>, easily creates a world map.</p>
  
  <pre><code>library(choroplethr)  
  library(choroplethrMaps)   # to obtain a map of the world
  library(ggplot2)
  library(riverplot)
  
  data(country.map)          # choose a world map
  world &lt;- ggplot(country.map, aes(long, lat, group=group)) + 
    geom_polygon(fill = "grey10") +
    theme_bw()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/2bSTd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2bSTd.png" alt="outline map of countries"></a></p>
  
  <p>But the riverplot foiled me, and even if I had gotten an overall plot working, <strong>is there code to make four of them (one for each LNG exporting region) and overlay them on the world map</strong>?</p>
  
  <pre><code>nodes.df &lt;- df
  nodes.df$ID &lt;- capwords(as.character(nodes.df$ID))
  nodes.df$ID &lt;- as.factor(nodes.df$ID)
  
  edges.df &lt;- df
  edges.df &lt;- setNames(edges.df, c("ID", "N1", "N2", "Value", "Color", "Region")) 
  
  edges.df &lt;- df[  , c("region", "x", "y", "value", "col", "region")]         #  use different ID names
  edges.df &lt;- setNames(edges.df, c("ID", "N1", "N2", "Value", "Color", "Region")) 
  
  
  river &lt;- makeRiver(nodes = nodes.df, edges = edges.df, node_labels = NULL,
                     node_xpos = nodes.df$x, node_ypos = nodes.df$y)
  
  Error in checkedges(edges, nodes$ID) : 
    edges must not have the same IDs as nodes
  </code></pre>