Closed dmongin closed 3 years ago
Thanks for your issue! I have added the argument value
to make long so that it also creates a weight column to be passed to ggsankey
where the aesthetic values
can be used. Reinstall ggsankey and try this reprex:
library(tidyverse)
library(ggsankey)
df <- data.frame(expand.grid(LETTERS[1:3],LETTERS[1:3]))
df$N <- sample(1:10,size = nrow(df),replace = T)
df <- df %>%
make_long(Var1, Var2, value = N)
df %>%
ggplot( aes(x = x,
next_x = next_x,
node = node,
next_node = next_node,
fill = factor(node),
value = value)) +
geom_sankey()
Created on 2021-05-25 by the reprex package (v2.0.0)
Whaou, perfect. Thank you for your reactivity and your work!
Great! How can I plot the values? Like under Node.
the below method works, what do you think?
df %>% count(x,node,next_x,next_node) %>% group_by(x,node) %>% mutate(cnt2 = sum(n)) %>% ggplot( aes(x = x, next_x = next_x, node = node, next_node = next_node, fill = factor(node), value = value, label = paste0(node,'\n',cnt2)) + #doesn't work geom_sankey()
Is there a way in
geom_sankey
to specify an aesthetic that provides directly the size of the flow, i.e. the number of connections between the nodes?For example:
I would like something like
But with the flows given by
N
. A hack would be to repeat each row by N before themake_long
, but I am sure there is a proper way.