ggplot R Sankey图,冲积层?

问题描述

我正在尝试使用冲积包装(https://cran.r-project.org/web/packages/ggalluvial/vignettes/ggalluvial.html)在R中制作Sankey图。到目前为止,我可以复制我发现的许多示例。但是,我专门尝试复制一些我没有看到的使用冲积包装的代码

基本上,数据集表示到达某个站点的人员(可能是任何东西),一些人进入下一个站点,有些人丢失(因此被截断)。在冲积包装中,我不知道该怎么做。我已经附上了它的外观快照(由http://sankeymatic.com/制造)。

我想应该很基本。我显示的图像中的另一件事是,我希望丢失的个人栏在每个节点上具有不同的颜色。

有人可以告诉我我需要的代码代码结构吗?

enter image description here

解决方法

您可以尝试使用包 PantaRhei

library(PantaRhei)
library(tibble)
library(grid)

# define node position

nodes <- 
  tribble(
~ID,~label,~x,~y,~label_pos,"s1","Station 1","1","0","below","s2a","Station 2: arrived","2","0.1","above","s2m","Station 2: missing","s3a","Station 3: arrived","3","0.2","s3m","Station 3: missing","s4a","Station 4: arrived","4","0.3","s4m","Station 4: missing","s5a","Station 5: arrived","5","0.4","s5m","Station 5: missing","below"
  )

# define size of flows

flows <-
  tribble(
    ~from,~to,~substance,~quantity,"a",80,"m",20,60,35,25,15,20
    )

# define flow colours

colors <- tribble(
  ~substance,~color,"green","red"
)

# node formating

ns <- list(type = "bar",gp=gpar(fill = "lightblue",col = "white",lwd = 1),mag_pos = "inside",mag_fmt = "%.0f")

# final sankey image
sankey(nodes,flows,colors,node_style = ns)

这给了你:

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...