在 plotly treemap 中的名称下方添加计数

Add Count below name in plotly treemap

有人可以告诉我如何制作一个 plotly treemap 来显示每个计数数字以获得类似于此图像的内容:

这是我正在使用的代码:

dtd1 <- structure(list(topic = c("Access control", "Access management",  "Cipher text", "Data encryption", "Data protection", "Data transmission", "Malware", "Malware analysis", "Network security", "Secret encoding", "Secret key", "Storage devices", "Wireless network"), n = c(42L,36L, 56L, 82L, 94L, 24L, 23L, 46L, 61L, 43L, 48L, 52L, 23L)), row.names = c(NA,  -13L), class = "data.frame")

ramp4 <- colorRamp(c("darkblue", "lightblue"))
ramp.list4 <- rgb( ramp4(seq(0, 1, length = 15)), max = 255)

p <- dtd1  %>% 
  plot_ly(labels = ~topic, 
          values = ~n, 
          parents = ~NA, 
          type = 'treemap',
          hovertemplate = "Cluster: %{label}<br>Count: %{value}<extra></extra>") %>%
  config(modeBarButtonsToRemove = list(
    "zoom2d",
    "pan2d",
    "zoomIn2d",
    "zoomOut2d",
    "autoScale2d",
    "resetScale2d",
    "hoverClosestCartesian",
    "hoverCompareCartesian",
    "sendDataToCloud",
    "toggleHover",
    "resetViews",
    "toggleSpikelines",
    "resetViewMapbox"),
    displaylogo = FALSE) %>%
  layout(title = "Patent scape",
         colorway = ramp.list4)
p

plotly library 中有 none 个图表,所以我不太清楚该去哪里看!

您可以简单地修改您的 label 如下:

dtd1 <- structure(list(topic = c("Access control", "Access management",  "Cipher text", "Data encryption", "Data protection", "Data transmission", "Malware", "Malware analysis", "Network security", "Secret encoding", "Secret key", "Storage devices", "Wireless network"), n = c(42L,36L, 56L, 82L, 94L, 24L, 23L, 46L, 61L, 43L, 48L, 52L, 23L)), row.names = c(NA,  -13L), class = "data.frame")

ramp4 <- colorRamp(c("darkblue", "lightblue"))
ramp.list4 <- rgb( ramp4(seq(0, 1, length = 15)), max = 255)

p <- dtd1  %>% 
  plot_ly(labels = ~ paste0(topic, "<br>", n), 
          values = ~n, 
          parents = ~NA, 
          type = 'treemap',
          hovertemplate = "Cluster: %{label}<extra></extra>") %>%
  config(modeBarButtonsToRemove = list(
    "zoom2d",
    "pan2d",
    "zoomIn2d",
    "zoomOut2d",
    "autoScale2d",
    "resetScale2d",
    "hoverClosestCartesian",
    "hoverCompareCartesian",
    "sendDataToCloud",
    "toggleHover",
    "resetViews",
    "toggleSpikelines",
    "resetViewMapbox"),
    displaylogo = FALSE) %>%
  layout(title = "Patent scape",
         colorway = ramp.list4)
p