Deepansh Arora
Deepansh Arora

Reputation: 742

Unable to change the labels on the tooltip

I am using plotly package to make a heatmap. However, the tooltips show "x,y,z" instead of "Base, weekday, count". Please guide me on how to fix this issue as I'm new to 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

enter image description here

Thanks!

Upvotes: 0

Views: 42

Answers (1)

ismirsehregal
ismirsehregal

Reputation: 33397

As you haven't provided any data I'm taking an example from here.

You can use plot_lys argument hovertemplate to modify the hoverinfo:

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

result

Upvotes: 1

Related Questions