我正在try 使用text =
和%{text}
在Ploly栏中显示myvar1
个值,并将其作为工具提示文本的一部分.然而,我的代码不能充分地生成工具提示,并且显示"%{Text}"而不是它的相应值(如下图所示).
以下是我的代码:
library(plotly)
dfcom <- data.frame(
myvar1 = c("Media", "Campaigns", "Website"),
alcance = c(6814511L, 400000L, 225329L),
type = c("viewers", "viewers", "viewers"))
plot_ly(
dfcom,
x = ~alcance, y = ~type,
text = ~myvar1,
textfont = list(color = I("white")),
type = 'bar',
color = ~myvar1,
colors = c("chartreuse4", "darkolivegreen", "darkgreen"),
showlegend = FALSE,
hovertemplate = "%{x:,.0f} people reached by %{text} <extra></extra>") %>%
layout(barmode = "stack")