Example code to make a Sankey chart with plotly
.
links <- data.frame(
source=c("group_A","group_A", "group_B", "group_C", "group_C", "group_E"),
target=c("group_C","group_D", "group_E", "group_F", "group_G", "group_H"),
value=c(2,3, 2, 3, 1, 3)
)
nodes <- data.frame(
name=c(as.character(links$source),
as.character(links$target)) %>% unique()
)
links$IDsource <- match(links$source, nodes$name)-1
links$IDtarget <- match(links$target, nodes$name)-1
plot_ly(
type = "sankey",
orientation = "h",
textfont = list(size=11),
node = list(
label = nodes$name,
pad = 15,
thickness = 20),
link = list(
source = links$IDsource,
target = links$IDtarget,
value = links$value))
Is it possible to add the ‘value’ on each link ? (See my photo 1 for example) :
I would also like to simplify the text on the hover. Indeed, I want to delete the “source” and “target” information and simply add this text :value : [links$value]
I have tried using hovertemplate
but apparently it is no longer a valid attributes. Here’s the expected output :
Thank you in advance.