【问题标题】:Add Count below name in plotly treemap在绘图树形图中在名称下方添加计数
【发布时间】:2021-01-02 06:51:14
【问题描述】:

有人可以告诉我如何制作一个有情节的树形图来显示每个计数数字以获得类似这样的图像:

这是我正在使用的代码:

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 中没有这些图表,所以我不完全知道在哪里看!

【问题讨论】:

    标签: plotly treemap r-plotly


    【解决方案1】:

    你可以简单地修改你的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
    

    【讨论】:

    • 你又来救我了! - 非常感谢你,你能分享这个图表的文档吗?
    • 不客气! Here 你可以找到一些额外的信息。还可以尝试运行 schema() 并导航到树形图跟踪。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-08
    • 2019-04-13
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    相关资源
    最近更新 更多