这是一个显示层次结构的优秀包。

根据 collapsibleTree Package 提供的文件

在下面的代码中,他在工具提示中使用了图像。

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"
)

这里每个气泡都显示一个图像。

在我的表中,每个员工都有一列图像。
javascript - R 可折叠树 : add images dynamically in tooltip-LMLPHP

现在例如 A Employee --> Image A 应该显示。
同样,它应该显示给所有员工。

是否可以。

任何建议将是可观的。

谢谢
莫汉五世

最佳答案



基于包作者的 example on GitHub ,这是每个节点不同图片的一张:

library(collapsibleTree)
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"
  )
)

# Add in colors and sizes
org$Color <- org$Title
levels(org$Color) <- colorspace::rainbow_hcl(11)

org$tooltip <- sprintf("
  %s<br>Title: %s<br><img src='%s'>",
  org$Employee,
  org$Title,
  paste0("https://github.com/twitter/twemoji/blob/gh-pages/72x72/1f19", c(1, 1:9, letters[1:6]), ".png?raw=true")
)

collapsibleTreeNetwork(
  org,
  attribute = "Title",
  fill = "Color",
  nodeSize = "leafCount",
  tooltipHtml = "tooltip"
)

javascript - R 可折叠树 : add images dynamically in tooltip-LMLPHP

关于javascript - R 可折叠树 : add images dynamically in tooltip,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47828655/

10-12 14:10