R编程:如何在plotly制作的条形图中添加数据标签?
R Programming: How to add data labels in bar graph made by 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)
)%>%
layout(title= paste("Monthly SOI Count of", clientName,"for the year",selectedYear, sep = " ") , xaxis = xQuartAxis, yaxis = yQuartAxis)
我希望现在问题看起来没问题?如果需要任何其他数据,请在下面评论。
谢谢!
是的,我得到了答案。这不是确切的答案,而是一个 hack,至少对我来说是有用的。
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)
谢谢:)
我正在使用 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)
我希望现在问题看起来没问题?如果需要任何其他数据,请在下面评论。
谢谢!
是的,我得到了答案。这不是确切的答案,而是一个 hack,至少对我来说是有用的。
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)
谢谢:)