0

我想在 R 中创建一个 sankey/冲积图。我有纵向数据:

id state time
1  s_1   t_1
1  s_2   t_5
1  s_3   t_10
2  s_1   t_1
2  s_3   t_9
3  s_1   t_1
3  s_2   t_4

我的代码:

df$id <- as.numeric(df$id)
df$state <- as.factor(df$state)
df$time <- as.factor(df$time)



ggplot(df, aes(x = time, stratum = state, alluvium = id, fill = state, label = state)) +
  geom_stratum() +
  geom_text(stat = "stratum", size = 3) +
  geom_flow(fill = "darkgrey", color = "black")

但我收到一个错误:

Data is not in a recognized alluvial form (see `help('alluvial-data')` for details).

我想我按照手动示例一步一步地做所有事情。5:

在此处输入图像描述

但是我还是看不懂剧情。有任何想法吗?

4

0 回答 0