简体   繁体   English

R计总计数

[英]R plotly total count

I have a plotly pie cart and a bar chart on my shiny dashboard and I was wondering if there is way to display 'total count' somewhere on the chart. 我闪闪发光的仪表板上有一个可口的饼车和一个条形图,我想知道是否有办法在图表的某处显示“总数”。 For instance, 例如,

Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 23)
data <- data.frame(Animals, SF_Zoo)
plot_ly(data, x = ~Animals, y = ~SF_Zoo, type = 'bar', name = 'SF Zoo')

I want to display 'Total Count = 57' in the plot somewhere 我想在某处的绘图中显示“总计数= 57”

thanks, 谢谢,

Manoj Agrawal 玛诺·阿格劳瓦尔(Manoj Agrawal)

You can try: The slice() function define where the text will be plotted. 您可以尝试: slice()函数定义将在何处绘制文本。

plot_ly(data, x = ~Animals, y = ~SF_Zoo, type = 'bar', name = 'SF Zoo') %>%
  slice(which.min(SF_Zoo)) %>%
  add_annotations(paste("Total=", sum(SF_Zoo)), showarrow=F, y=20)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM