9

The fascinating chart below is in the Economist, 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 riverplots) but with arrows reversed as the depicted arrow heads? Meaning, the flows into the exporting region would show as flowing out.

Economist map with flows

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.

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

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 choroplethr and its complement, choroplethrMaps, easily creates a world map.

library(choroplethr)  
library(choroplethrMaps)   # to obtain a map of the world
library(ggplot2)
library(riverplot)

data(country.map)          # choose a world map
world <- ggplot(country.map, aes(long, lat, group=group)) + 
  geom_polygon(fill = "grey10") +
  theme_bw()

outline map of countries

But the riverplot foiled me, and even if I had gotten an overall plot working, is there code to make four of them (one for each LNG exporting region) and overlay them on the world map?

nodes.df <- df
nodes.df$ID <- capwords(as.character(nodes.df$ID))
nodes.df$ID <- as.factor(nodes.df$ID)

edges.df <- df
edges.df <- setNames(edges.df, c("ID", "N1", "N2", "Value", "Color", "Region")) 

edges.df <- df[  , c("region", "x", "y", "value", "col", "region")]         #  use different ID names
edges.df <- setNames(edges.df, c("ID", "N1", "N2", "Value", "Color", "Region")) 


river <- 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
4

2 回答 2

0

您可以单独创建桑基图,将它们保存为 PNG,重新导入它们并使用 grid.raster 将它们粘贴到地图上。它与使用 Illustrator 一样耗费人力,但至少它是程序化的(例如,准备好进行数据更新)。当我们需要将桑基图与其他类似的图形结合起来时,我们之前在我的工作中做过这个。

于 2017-01-06T02:16:42.380 回答
0

您可以使用https://www.mapprovision.com/来执行此操作。

它采用如下所示的数据,然后完成其余的工作。

示例数据

这是一个例子:

桑基地图示例

这里有一个分步指南:

https://mapprovision.blogspot.com/2020/01/how-to-create-your-own-world-sankey-maps.html

  • 免责声明 - 我在 MapProvision 工作
于 2020-03-29T06:23:47.513 回答