Guest User

Untitled

a guest
Dec 17th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. library(plotly)
  2. library(bupaR)
  3. library(tidyverse)
  4.  
  5. # get the unique nodes
  6. patients <- mutate(patients, employee = toupper(employee))
  7.  
  8. nodes <- sort(unique(c(as.character(patients$employee), as.character(patients$handling))))
  9.  
  10. count(patients, employee, handling) %>% # count pairs
  11. complete(employee, handling, fill=list(n=0)) %>% # have an entry for each pair combo
  12. mutate(employee = factor(employee, levels=nodes)) %>% # these two lines
  13. mutate(handling = factor(handling, levels=nodes)) -> sdf # make it possible to get numeric values for the nodes
  14.  
  15. list(
  16. type = "sankey",
  17. domain = c(
  18. x = c(0,1),
  19. y = c(0,1)
  20. ),
  21. node = list(label = nodes),
  22. link = list(
  23. source = as.numeric(sdf$employee)-1,
  24. target = as.numeric(sdf$handling)-1,
  25. value = sdf$n,
  26. label = sprintf("Case%d", 1:nrow(sdf))
  27. )
  28. ) -> trace1
  29.  
  30. plot_ly(
  31. domain=trace1$domain, link=trace1$link,
  32. node=trace1$node, type=trace1$type
  33. )
Add Comment
Please, Sign In to add comment