Giter Site home page Giter Site logo

Comments (2)

AdeelK93 avatar AdeelK93 commented on August 24, 2024

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.

AdeelK93 avatar AdeelK93 commented on August 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.