Comments (2)
Thank you, and happy you're finding the package useful!
I imagine your org chart can be represented as a series of parent-child relations, in which case you can help use data.tree
to help turn your table into a hierarchal structure. As for multi-line labels, just use an html <br/>
tag, and use the identity
function for aggregation.
How does this look?
# Using a flat relationship-style data frame with tooltips
Relationships <- data.frame(
Parent=c("Alice","Alice","Bob", "Bob", "Bob", "B", "B", "C", "E", "E", "F", "Susan", "Susan", "M", "M"),
Child=c("Bob","Susan","B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "M", "N", "O"),
Title=c("Senior<br/>Manager","Manager","B", "C", "D", "E", "F", "G", "H", "I", "J", "L", "M", "N", "O")
)
tree <- data.tree::FromDataFrameNetwork(Relationships, "Title")
# Define root node value as 0
tree$Title <- "Director"
# Create tree diagram with the aggregation function of identity
collapsibleTree(
tree,
tooltip = TRUE,
attribute = "Title",
aggFun = identity,
collapsed = FALSE,
fill = colorspace::terrain_hcl(16)
)
from collapsibletree.
I decided to create a convenience function for this sort of data structure, and implemented better tooltip support for it. It's in the github version, let me know what you think!
# devtools::install_github("AdeelK93/collapsibleTree")
# Create a simple org chart
org <- data.frame(
Manager = c(
NA, "Ana", "Ana", "Bill", "Bill", "Bill", "Claudette", "Claudette", "Danny",
"Fred", "Fred", "Grace", "Larry", "Larry", "Nicholas", "Nicholas"
),
Employee = c(
"Ana", "Bill", "Larry", "Claudette", "Danny", "Erika", "Fred", "Grace",
"Henri", "Ida", "Joaquin", "Kate", "Mindy", "Nicholas", "Odette", "Peter"
),
Title = c(
"President", "VP Operations", "VP Finance", "Director", "Director", "Scientist",
"Manager", "Manager", "Jr Scientist", "Operator", "Operator", "Associate",
"Analyst", "Director", "Accountant", "Accountant"
)
)
collapsibleTreeNetwork(org, attribute = "Title")
# Add in colors and sizes
org$Color <- org$Title
levels(org$Color) <- colorspace::rainbow_hcl(11)
collapsibleTreeNetwork(
org,
attribute = "Title",
fill = "Color",
nodeSize = "leafCount",
collapsed = FALSE
)
# Use unsplash api to add in random photos to tooltip
org$tooltip <- paste0(
org$Employee,
"<br>Title: ",
org$Title,
"<br><img src='https://source.unsplash.com/collection/385548/150x100'>"
)
collapsibleTreeNetwork(
org,
attribute = "Title",
fill = "Color",
nodeSize = "leafCount",
tooltipHtml = "tooltip",
collapsed = FALSE
)
from collapsibletree.
Related Issues (20)
- collapsibleTreeSummary: Change Color of clicked node?
- Disappearing nodes
- is there a way to embed node labels inside a node and space out nodes more? HOT 3
- [feature requested] Reverse Tree
- Trigger collapsible tree by shiny inputs
- deprecated Node$fields HOT 4
- collapsibleTreeSummary Function - Allow for different agg functions
- Open tree sideways or in circular format
- [question] same attributes displayed at the same level
- [feature request] Allow map to be partially un-collapsed by default
- Link in tooltip HOT 5
- Add node values from dataframe
- Where can we find `Geography` dataset? HOT 2
- Change text colour and branch colour
- Changing the node size scale HOT 1
- tooltipHtml for collapsibleTreeSummary? HOT 1
- Generate collapsible tree from `hclust` objects
- Search Bar and "Zoom Out"
- Including colors based on a particular node
- dynamically create branch from clicked node?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from collapsibletree.