2016-07-16 59 views
-3

我正在积极创建条形图。但想知道如何在条形图的顶部添加数据标签?R编程:如何通过绘制添加条形图中的数据标签?

在下面的条形图中,我想在条形图上添加各个数据标签。

我使用生成柱状图验证码:

plot_ly(
     x = as.vector(de$MO), 
     y = de$CNT, 
    text = a, hoverinfo = "text", mode="y", type = "bar", 
     name = "SF Zo", 
     color = as.character(de$MO) 
    )%>% 
     layout(title= paste("Monthly SOI Count of", clientName,"for the year",selectedYear, sep = " ") , xaxis = xQuartAxis, yaxis = yQuartAxis) 

Plot Created Using Plotly

我希望现在的问题看起来不错?如果需要其他数据,请在下面评论。

谢谢!

+0

你的问题不积极参与:你没有解释为什么这是一个问题,你是否尝试过任何自己到目前为止,而不是提供一个工作的例子。 [本页](http://stackoverflow.com/help/how-to-ask)可能会对您有所帮助。 – sebastianmm

+0

@sebastianmm对不起,我正在更新这个问题。 –

回答

1

是的,我得到了答案。这不是确切的答案,而是至少对我来说证明有用的黑客攻击。

plot_ly(
     x = as.vector(de$MO), 
     y = de$CNT, 
    text = a, hoverinfo = "text", mode="y", type = "bar", 
     name = "SF Zo", 
     color = as.character(de$MO) 
    )%>% 
     add_trace(data=de, x=as.vector(de$MO), y=de$CNT, mode="text",text=a, hoverinfo='none',textposition = "top middle", showlegend = FALSE)%>% 
     layout(title= paste("Monthly SOI Count of", clientName,"for the year",selectedYear, sep = " ") , xaxis = xQuartAxis, yaxis = yQuartAxis) 

谢谢:)

相关问题