3

This is an excellent package to show hierarchy levels.

as per provided document of 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. enter image description here

Now for example A Employee --> Image A should be show. Likewise it should show for all the employees.

Is it possible.

Any suggestions will be appreciable.

Thanks Mohan V

Bunny
  • 409
  • 3
  • 21
  • To avoid ambiguity, you should always provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/28481250#28481250) as asked by the R tag (hover over it) instead of data screenshots and incomplete code – lukeA Dec 15 '17 at 12:00

1 Answers1

5

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:

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

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • Thanks for the reply @lukeA. this is super cool..but as i mentioned in my question that..i have a column of having image urls of each employee, and i would like to show those images in tooltip..so can you please suggest me how can i show those column image urls in here. – Bunny Dec 15 '17 at 10:17
  • Can you please let me know what does c(1, 1:9, letters[1:6]), ".png?raw=true") this means – Bunny Dec 15 '17 at 11:47
  • @Bunny replace `paste0("https://github.com/twitter/twemoji/blob/gh-pages/72x72/1f19", c(1, 1:9, letters[1:6]), ".png?raw=true")` with `org$Image`. – lukeA Dec 15 '17 at 11:58
  • Thats perfect...i have seen the output and the values are as expected, But a small issue is, images are not loading..it is showing question mark at everywhere. i have checked those paths and they are working fine when i open those links. is there any format for those images that needs to be followed...or datatype?? – Bunny Dec 15 '17 at 12:55
  • @Bunny Open it in a browser instead of RStudio; if that does not work, edit your question and provide a reproducible example. – lukeA Dec 15 '17 at 13:19