R collapsibleTree:在工具提示中动态添加图像

时间:2017-12-15 08:44:23

标签: javascript html r

这是显示层次结构级别的绝佳包。

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

此处每个气泡都会显示一张图片。

在我的表中,每个员工都有一列图像。 enter image description here

现在例如A Employee - &gt;应该显示图像A. 同样,它应该显示给所有员工。

是否可能。

任何建议都会很明显。

由于 Mohan V

1 个答案:

答案 0 :(得分:3)

  

此处每个气泡都会显示一张图片。 [...]我们能展示吗?   动态地将这些图像发送给他们尊重的员工泡沫。

根据软件包作者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"
)

enter image description here