简体   繁体   English

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

[英]R collapsibleTree: add images dynamically in tooltip

This is an excellent package to show hierarchy levels. 这是一个显示层次结构级别的优秀包。

as per provided document of collapsibleTree Package 根据collapsibleTree Package提供的文档

Here in below code he has used a image in 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"
)

Here a single image is shown at every bubble. 这里每个气泡都会显示一个图像。

In my table i have a column of images per each Employee. 在我的表中,每个员工都有一列图像。 在此输入图像描述

Now for example A Employee --> Image A should be show. 现在例如A Employee - > Image A应该显示。 Likewise it should show for all the employees. 同样,它应该显示给所有员工。

Is it possible. 可能吗。

Any suggestions will be appreciable. 任何建议都会很明显。

Thanks Mohan V 谢谢Mohan V.

Here a single image is shown at every bubble. 这里每个气泡都会显示一个图像。 [...] Can we show dynamically those images to their respected employee bubble. [...]我们能否将这些图像动态显示给他们尊重的员工泡沫。

Based on the package author's example on GitHub , here's one with different pictures per node: 基于包作者在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"
)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM