0

I would like to create a sankey/alluvial diagram in R. I have longitudal data:

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

My code:

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

But I receive an error:

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

I think I do everything step by step following the manual example no. 5:

enter image description here

But I still can't get the plot. Any ideas?

Tom
  • 339
  • 2
  • 9
  • 1
    Hm. I can't reproduce your error. Based on your example data your code works fine. – stefan Nov 20 '20 at 08:34
  • Thank you for a check. I can't still figure it out. I'll check for a package conflict and updates – Tom Nov 23 '20 at 13:10

0 Answers0