在可绘制的甜甜圈图中隐藏标签 [英] Hide labels in plotly donut chart r

查看:47
本文介绍了在可绘制的甜甜圈图中隐藏标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Shiny应用程序,在其中绘制了甜甜圈图.切片取决于所选的变量,有时会太小.在这种情况下,标签将显示在图表外部,如下图所示.

是否有一种方法可以完全隐藏图表中的所有标签(带有%符号的值),而仅允许悬停操作显示详细信息?

甜甜圈图的可复制代码如下:

 库(可打印)图书馆(tidyr)图书馆(dplyr)#获取制造商mtcars $ manuf<-sapply(strsplit(rownames(mtcars),"),"[[",1)p<-mtcars%&%;%group_by(manuf)%&%;%汇总(count = n())%&%plot_ly(labels =〜manuf,values =〜count)%&%;%add_pie(hole = 0.6)%&%;%布局(标题=使用Plotly的甜甜圈图",showlegend = F,xaxis = list(showgrid = FALSE,零线= FALSE,showticklabels = FALSE),yaxis = list(showgrid = FALSE,零线= FALSE,showticklabels = FALSE))p 

解决方案

您可以设置

I am working on a Shiny app where I am plotting a Donut chart. The slices depend on the variable selected and sometimes are too small. In such cases the labels are displayed outside the chart like in the image below.

Is there a way to altogether hide all the labels (values with % sign) in the chart and only allow the hover action to show the details?

An reproducible code for a Donut Chart is as below:

library(plotly)
library(tidyr)
library(dplyr)
# Get Manufacturer
mtcars$manuf <- sapply(strsplit(rownames(mtcars), " "), "[[", 1)

p <- mtcars %>%
  group_by(manuf) %>%
  summarize(count = n()) %>%
  plot_ly(labels = ~manuf, values = ~count) %>%
  add_pie(hole = 0.6) %>%
  layout(title = "Donut charts using Plotly",  showlegend = F,
         xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
         yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))

p

解决方案

You could set textinfo='none' to get the following donut plot which has no text in the pie elements but shows info on hovering.

这篇关于在可绘制的甜甜圈图中隐藏标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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