无法更改工具提示上的标签

Unable to change the labels on the tooltip

我正在使用 plotly 包制作热图。但是,工具提示显示“x,y,z”而不是“Base, weekday, count”。请指导我如何解决这个问题,因为我是 plotly package 的新手。我的代码是:

p<-plot_ly(x=colnames(df_base_dayofweek_m), y=rownames(df_base_dayofweek_m), z = df_base_dayofweek_m, type = "heatmap") %>%
  layout(margin = list(l=120))
p <- p %>% layout(title = 'Ride count for different bases',margin=m,
                  titlefont = list(size = 38, color = "black", family = "Calibri"),
                      xaxis = list(title = 'Bases',tickfont = list(size = 15), ticktext = sprintf("<b>%s</b>",
                      levels(factor(df_base_dayofweek_label$Base))),
                      tickvals = levels(factor(df_base_dayofweek_label$Base)),
                      titlefont = list(color = "black",size = 28, family = "Arial")),
                      yaxis = list(title = 'Weekday',tickfont = list(size = 15),ticktext = sprintf("<b>%s</b>",
                               levels(factor(df_base_dayofweek_label$dayofweek))),
                               tickvals = levels(factor(df_base_dayofweek_label$dayofweek)), 
                               titlefont = list(color = "black",size = 28,family = "Arial")))
p

谢谢!

由于您没有提供任何数据,我以 here 中的示例为例。

您可以使用 plot_ly 的参数 hovertemplate 修改悬停信息:

library(plotly)
fig <- plot_ly(z = volcano,
          type = "heatmap",
          hovertemplate = "Base: %{x}<br>Weekday: %{y}<br>Count: %{z}<extra></extra>")
fig