-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A legend for Sankey networks #240
Comments
I don't believe anyone is working on that, but suppose we'd be open to PRs for it. |
Hello, I faced the same issue. Here's the way to add a legend. You first need to create a d3.js code and store in the working directory. This d3.js code will create a legend, I started from the description in https://www.d3-graph-gallery.com/graph/custom_legend.html (section: categorical legend, use a loop). the d3.js could be called in R using r2d3::r2d3() function. Then you need the function manipulateWidget::combineWidgets() to pair the sankey from sankeyNetwork and the legend. I hope this could be useful for implementing a legend = T argument within the sankeyNetwork function. Here's an example: // Usually you have a color scale in your chart already // Add one dot in the legend for each name. // Add one dot in the legend for each name. and here's the R code: links <- data.frame( nodes <- data.frame( links$IDsource <- match(links$source, nodes$name)-1 links$group <- as.factor(c("type_a","type_a","type_a","type_b","type_b","type_b")) # Add a 'group' column to each connection: my_color <- 'd3.scaleOrdinal() .domain(["type_a", "type_b", "my_first_group", "my_second_group"]) .range(d3.schemeCategory10)' sankey <- sankeyNetwork(Links = links, Nodes = nodes, Source = "IDsource", Target = "IDtarget", legend <- r2d3(data = unique(c(links$group, nodes$group)), script = "legend_test.js") # legend combineWidgets(sankey, legend, ncol = 2, colsize = c(5,1)) # Combine plots |
Any plans for
sankeyNetwork(NodeGroup = "column_with_color", legend = TRUE)
?The text was updated successfully, but these errors were encountered: