在绘图树图中的名称下方添加计数 [英] Add Count below name in plotly treemap

查看:55
本文介绍了在绘图树图中的名称下方添加计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是我正在使用的代码:

dtd1 <- structure(list(topic = c(访问控制"、访问管理"、密文"、数据加密"、数据保护"、数据保护")数据传输"、恶意软件"、恶意软件分析"、网络安全"、秘密编码"、密钥"、存储设备"、无线网络"),n = c(42L,36L, 56L, 82L, 94L, 24L, 23L, 46L, 61L, 43L, 48L, 52L, 23L)), row.names = c(NA, -13L), class = "data.frame")斜坡4 <- colorRamp(c(深蓝色",浅蓝色"))斜坡.list4 <- rgb(ramp4(seq(0, 1, length = 15)), max = 255)p<-dtd1%>%plot_ly(labels = ~topic,值 = ~n,父母 = ~NA,type = '树状图',悬停模板 =集群:%{label}
计数:%{value}")%>%配置(modeBarButtonsToRemove = 列表(zoom2d",pan2d",zoomIn2d",zoomOut2d",autoScale2d",resetScale2d",hoverClosestCartesian",悬停比较笛卡尔","sendDataToCloud",切换悬停",重置视图",切换尖峰线",resetViewMapbox"),displaylogo = FALSE) %>%布局(标题=专利景观",配色 = 斜坡.list4)磷

Could somebody please tell me how I can make a plotly treemap to display each count number to get something like this image:

Here's the code I'm working with:

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

There's none of this graphs in plotly library so I'm not completely aware about where to look!

解决方案

You can simply modify your label as follows:

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

这篇关于在绘图树图中的名称下方添加计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆