Hi all,
I have a same data with treemap constructed. Everything is working as expected. But lacks one feature. There are links in the dataframe. When the user clicks on the respective blocks, the url should be opened
library(plotly)
dtd7 <- structure(
list(
topic = structure(
c(9L, 8L, 4L, 7L, 2L, 6L, 1L, 3L,
5L, 10L, 13L, 11L, 12L),
.Label = c("Apple", "Avocado", "Banana", "Carrot", "Mango","Mushroom", "Onion", "Orange", "Pineapple", "Strawberry", "Sweet-lemon", "Watermelon", "Wildberry"),
class = "factor"
),
n = structure(
c(4L, 3L, 9L, 11L, 12L, 2L, 1L, 6L, 10L, 5L,
7L, 8L, 1L),
.Label = c("23", "24", "36", "42", "43", "46", "48", "52", "56", "61", "82", "94"),
class = "factor"
),
link = structure(c("<a href = 'https://www.google.co.in/'>google</a>","<a href = 'https://www.google.co.in/'>google</a>",
"<a href = 'https://www.google.co.in/'>google</a>","<a href = 'https://www.google.co.in/'>google</a>",
"<a href = 'https://www.google.co.in/'>google</a>","<a href = 'https://www.google.co.in/'>google</a>",
"<a href = 'https://www.google.co.in/'>google</a>","<a href = 'https://www.google.co.in/'>google</a>",
"<a href = 'https://www.amazon.co.in/'>google</a>","<a href = 'https://www.google.co.in/'>google</a>",
"<a href = 'https://www.google.co.in/'>google</a>","<a href = 'https://www.google.co.in/'>google</a>",
"<a href = 'https://www.google.co.in/'>google</a>"))
),
class = "data.frame",
row.names = c(NA,-13L)
)
p <- plot_ly(
dtd7,
labels = ~ topic,
parents = NA,
values = ~ n,
type = 'treemap',
hovertemplate = "Ingredient: %{label}<br>Count: %{value}<extra></extra>"
)
p