[英]Unable to change the labels on the tooltip
I am using plotly package to make a heatmap.我正在使用 plotly package 制作热图。 However, the tooltips show "x,y,z" instead of "Base, weekday, count".
但是,工具提示显示“x,y,z”而不是“Base, weekday, count”。 Please guide me on how to fix this issue as I'm new to plotly package.
请指导我如何解决此问题,因为我是 plotly package 的新手。 My code is:
我的代码是:
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
Thanks!谢谢!
As you haven't provided any data I'm taking an example from here .由于您没有提供任何数据,我从这里举个例子。
You can use plot_ly
s argument hovertemplate
to modify the hoverinfo:您可以使用
plot_ly
的参数hovertemplate
来修改 hoverinfo:
library(plotly)
fig <- plot_ly(z = volcano,
type = "heatmap",
hovertemplate = "Base: %{x}<br>Weekday: %{y}<br>Count: %{z}<extra></extra>")
fig
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.