2016-07-16 80 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) 

謝謝:)

相關問題