R编程:如何在plotly制作的条形图中添加数据标签?

R编程:如何在plotly制作的条形图中添加数据标签?,r,charts,shiny,plotly,R,Charts,Shiny,Plotly,我正在使用plotly创建条形图。但是想知道如何在条形图顶部添加数据标签吗 在下面的条形图中,我想在条形图上添加单独的数据标签 我使用以下代码生成条形图: 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)

我正在使用plotly创建条形图。但是想知道如何在条形图顶部添加数据标签吗

在下面的条形图中,我想在条形图上添加单独的数据标签

我使用以下代码生成条形图:

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_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)

谢谢:)

你的问题不引人入胜:你没有解释为什么这是一个问题,你自己是否尝试过任何东西,也没有提供一个有效的例子。可能对你有帮助。@sebastianmm很抱歉,我正在更新这个问题。