Last active
July 10, 2017 10:54
-
-
Save stephlocke/6e525df9024346271ecaa15af674af78 to your computer and use it in GitHub Desktop.
Trying to make a staff hierarchy in DiagrammeR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(readr) | |
library(DiagrammeR) | |
staff <- read_csv( | |
"ID,Name,Title,ManagerID | |
1,Jane,CEO, | |
2,Bill,CIO,1 | |
3,Lydia,CTO,1 | |
4,Jack,CMO,1 | |
5,Anne,Data Scientist,2 | |
6,Rhodri,Head of Security,2 | |
7,Chris,Security Analyst,6" | |
) | |
staff %>% | |
filter(!is.na(ManagerID)) %>% | |
select(from = ManagerID, to = ID) -> | |
edges | |
# Doesn't work | |
staff %>% | |
mutate(label = paste0(Name, "\n", Title), | |
shape = "square", type=NA) %>% | |
select(id = ID, label,shape, type) -> | |
nodes | |
hierarchy <- create_graph(nodes_df = nodes, | |
edges_df = edges) | |
render_graph(hierarchy) | |
# Doesn't work | |
staff %>% | |
mutate(label = paste0(Name, "\n", Title), | |
shape = "square", type=NA) %>% | |
select(nodes = ID, label,shape, type) -> | |
nodes | |
hierarchy <- create_graph(nodes_df = nodes, | |
edges_df = edges) | |
render_graph(hierarchy) | |
# Sorta works | |
staff %>% | |
mutate(label = paste0(Name, "\n", Title), | |
shape = "square") %>% | |
select(nodes = ID, everything(), -ManagerID) -> | |
nodes | |
hierarchy <- create_graph(nodes_df = nodes, | |
edges_df = edges) | |
render_graph(hierarchy) | |
# Works | |
hierarchy <- create_graph(nodes_df = create_node_df(7,label = nodes$label,shape=nodes$shape), | |
edges_df = edges) | |
render_graph(hierarchy) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment