我正在使用R,并试图将x、y或z以外的变量添加到我的Plotly hovertemplate中。
在下面的示例代码中,我想向悬停添加一个变量weight,但没有找到这样做的方法(当前代码只显示字符串“{weight}”,而不是weight变量的值)。
我在Python中看到了一个解决方案,但不是R。非常感谢您的任何建议。非常感谢。
library(plotly)
library(tidyverse)
my_tibble <- tibble(mins = runif(10,10,30),
week = 1:10,
exercise = c("a", "b", "b", "b", "a", "a", "b", "b", "b", "a"),
weight = runif(10,150,160))
example_hex <- c('#70AD47', '#404040', '#CAE1F1', '#24608B')
plot_ly(
data = my_tibble,
type = 'bar',
x = ~week,
y = ~mins,
color = ~exercise,
colors = example_hex,
hovertemplate = paste('<b>Week</b>: %{x}',
"%{weight}",
'<extra></extra>')
)