Skip to content
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

Add examples #1

Open
5 of 8 tasks
SchmidtPaul opened this issue Aug 3, 2023 · 4 comments
Open
5 of 8 tasks

Add examples #1

SchmidtPaul opened this issue Aug 3, 2023 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@SchmidtPaul
Copy link
Owner

SchmidtPaul commented Aug 3, 2023

The Examples page should have examples for

  • create a diagram asap
  • Labels and Values
  • Link color & Node color
  • Node Positioning
  • x-axis labels
  • value label formatting
  • node padding (the one below)
  • recreating some other public Sankey plots
@SchmidtPaul
Copy link
Owner Author

Hey @kenneditodd, could I ask you for your input on this? Can you install the package and recreate the examples? What else are you interested in?

@SchmidtPaul SchmidtPaul added the documentation Improvements or additions to documentation label Aug 3, 2023
SchmidtPaul added a commit that referenced this issue Aug 3, 2023
@kenneditodd
Copy link

kenneditodd commented Aug 3, 2023

@SchmidtPaul Your examples page says 404 - page not when you click on the link from the main README. However, the link from this page works and I was able to replicate all the examples. Things off the top of my head is i need the nodes to almost repel eachother for a cleaner display. Also, when zooming and dragging nodes a reset button would be nice. Kinda like what you see with plotly graphs.

@kenneditodd
Copy link

kenneditodd commented Aug 3, 2023

So, using the following code i generated this graph.

# Links table
links <- tribble(
  ~source, ~target, ~value, ~linkcolor,
  0,       1,       3510683,    "gray", # ccs to extract hifi
  1,       2,       3089255,    "gray", # extract hifi to lima passed
  1,       3,       421428,     "gray", # extract hifi to lima failed
  2,       4,       3036889,    "gray", # lima passed to refine passed
  2,       5,         52366,    "gray", # lima passed to refine fail
  4,       6,       157826,     "gray", # refine passed to cluster HQ
  4,       7,           44,     "gray", # refine passed to cluster LQ
  6,       8,        57528,     "gray", # cluster HQ to collapse
  8,       9,        57528,     "gray", # collapse to classify       
  9,      10,        40201,     "gray", # classify to filter   
  6,      11,       157761,     "gray", # cluster HQ to mapped          
  6,      12,           65,     "gray", # cluster HQ to did not map
 11,      13,       157761,     "gray"  # mapped to bambu
)

# Nodes table
nodes <- tribble(
  ~id, ~label,                  ~nodecolor,    ~yorder,
  0,   "CCS",                   "skyblue",           1,
  1,   "Extract HiFi",          "skyblue",           1,
  2,   "Lima Passed",           "skyblue",           1,
  3,   "Lima Failed",           "black",             2,
  4,   "Refine Passed",         "skyblue",           1,
  5,   "Refine Failed",         "black",             2,
  6,   "Cluster HQ",            "skyblue",           2,
  7,   "Cluster LQ",            "black",             1,
  8,   "Collapse",              "red",               1,
  9,   "Classify",              "red",               1,
  10,  "Filter",                "red",               1,
  11,  "Mapped",                "gold",              2,
  12,  "Did not map",           "black",             3,
  13,  "Bambu",                 "gold",              2
)

# Plot
sankeyNetwork(
  Links = links,
  Source = "source",
  Target = "target",
  Value = "value",
  linkColor = "linkcolor",
  Nodes = nodes,
  NodeID = "label",
  NodeColor = "nodecolor",
  NodePosY = "yorder",
  numberFormat = ",.0f"
)
image

But I want it to be more like this without manually adjusting (it will be in shiny app). The width of the link is equal to the size of the node. I was wondering if the width of the link could be adjusted. It would be nice to pass a value, maybe a percentage of the node size, to the links table. Also I have crowding that I can manually adjust but even after I play around with y-axis ordering, it still doesn't look as good as when I manually move them.

image

@SchmidtPaul
Copy link
Owner Author

Thanks for your input @kenneditodd !

  1. I fixed the 404.
  2. I think repelling nodes should work via increasing the nodePadding. I have a reprex below where I do that and also change a few yorder in your example to obtain an improved plot without needing to manually drag around stuff.
  3. I'm afraid I actually don't have a big focus on using these in a shiny app but I think you could just set up a reset button so that the sankeyNetwork() function itself runs again.
library(sankeyD3plus)
library(tibble)

# Links table
links <- tribble(
  ~source, ~target, ~value, ~linkcolor,
  0,       1,       3510683,    "gray", # ccs to extract hifi
  1,       2,       3089255,    "gray", # extract hifi to lima passed
  1,       3,       421428,     "gray", # extract hifi to lima failed
  2,       4,       3036889,    "gray", # lima passed to refine passed
  2,       5,         52366,    "gray", # lima passed to refine fail
  4,       6,       157826,     "gray", # refine passed to cluster HQ
  4,       7,           44,     "gray", # refine passed to cluster LQ
  6,       8,        57528,     "gray", # cluster HQ to collapse
  8,       9,        57528,     "gray", # collapse to classify       
  9,      10,        40201,     "gray", # classify to filter   
  6,      11,       157761,     "gray", # cluster HQ to mapped          
  6,      12,           65,     "gray", # cluster HQ to did not map
  11,      13,       157761,    "gray"  # mapped to bambu
)

# Nodes table
nodes <- tribble(
  ~id, ~label,                  ~nodecolor,    ~yorder,
  0,   "CCS",                   "skyblue",           1,
  1,   "Extract HiFi",          "skyblue",           1,
  2,   "Lima Passed",           "skyblue",           2, # changed
  3,   "Lima Failed",           "black",             1, # changed
  4,   "Refine Passed",         "skyblue",           2, # changed
  5,   "Refine Failed",         "black",             1, # changed
  6,   "Cluster HQ",            "skyblue",           2,
  7,   "Cluster LQ",            "black",             1,
  8,   "Collapse",              "red",               1,
  9,   "Classify",              "red",               1,
  10,  "Filter",                "red",               1,
  11,  "Mapped",                "gold",              2,
  12,  "Did not map",           "black",             3,
  13,  "Bambu",                 "gold",              2
)

# Plot
sankeyNetwork(
  Links = links,
  Source = "source",
  Target = "target",
  Value = "value",
  linkColor = "linkcolor",
  Nodes = nodes,
  NodeID = "label",
  NodeColor = "nodecolor",
  NodePosY = "yorder",
  numberFormat = ",.0f",
  nodePadding = 50
)

Created on 2023-08-04 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants