I am trying to plot treemap for topic and sub-topic level. So that inside each topic block, there needs to be subtopic as per the values. For example, topic "ty" should be a huge block since the sum of value "n" is more. Under this block there should be sub blocks with respective to Sub_topics? Is this possible to achieve?
library(plotly)
library(readxl)
dtd7 <- structure(list(topic = c("sf", "sf", "sf", "fgds", "fgds", "ty",
"ty", "ty", "ty", "ty"), Sub_topic = c("a", "b", "c", "a", "b",
"a", "b", "c", "d", "e"), n = c(3, 1, 5, 3, 1, 6, 4, 6, 3, 1)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
# Book1 <- read_excel("Book1.xlsx")
dtd7 <- as.data.frame(Book1)
p <- plot_ly(
dtd7,
labels = ~ topic,
parents = ~ Sub_topic,
values = ~ n,
type = 'treemap'
# ,hovertemplate = "Ingredient: %{label}<br>Count: %{value}<extra></extra>"
)
p