Removing hovertext from add_text when “compare data on hover”

I am facing an issue when click on "Compare data on hover". I add the string hoverinfo="none" on the add_text function, but when I click over "Compare data on hover" the hovertext anyhow is displayed. Therefore, I have twice hovertext, on comming from the bar and Markers and the duplication coming from the "add_text" function. Attached u will find an image.

Can anyone help me to get rid of this ?

I'll really appreciate :slight_smile:

here the code:

library(plotly)
t <- list(
  family = "Century Gothic",
  size = 10,
  color = "Black")

x<-c("Menor de 1","de 1 a 10","de 11 a 20","de 21 a 30","de 31 a 40", "de 41 a 50","de 51 a 60",
                      "de 61 a 70","de 71 a 80","de 81 a 90","de 91 a 100","Mayores de 100")

xform <- list(categoryorder = "array",
              categoryarray = x, title="Rango de Edad")

fig<- plot_ly(arEdad, x =~x , y = ~Positivos, type = "bar", name="Positivos",
              hovertemplate = paste('<b>%{x}</b> años', '<br><b>Positivos:</b>',arEdad$Positivos,'<br>',
                                                '<b>%/Total:</b> ',arEdad$Porc_Positivos,'<br>'),hoverinfo="none") 
fig <- fig %>% add_text(hoverinfo="none",textfont = t, textposition = "top",text = ~Positivos,texttemplate = '%{y:.f}',showlegend=FALSE)
fig<- fig %>%  add_trace( y = ~Muertos,  yaxis = "y2", type="scatter",name = "Muertos",mode="markers+lines",
                          hovertemplate = paste('<b>%{x}</b> años', '<br><b>Fallecidos:</b>',arEdad$Muertos,'<br>',
                                                '<b>%/Total:</b> ',arEdad$Porc_Muertos,'<br>','<b>Muertos/Positivos:</b> ',arEdad$Porc_Muertos_Positivos,'<br>'))
fig <- fig %>% add_text(hoverinfo="none",y=arEdad$Muertos,yaxis = "y2",textfont = t, textposition = "top",text = ~Muertos,texttemplate = '%{y:.f}',showlegend=FALSE)
fig<- fig %>%  layout(yaxis2 = list(overlaying = "y", side = "right"),xaxis = xform , yaxis=list(title="Cantidad de Personas"))


fig

Dataset

> arEdad
          Positivos Muertos Porc_Positivos Porc_Muertos Porc_Muertos_Positivos
Menor_1        1050       4        0.723 %      0.074 %                0.381 %
de_1_10        7478      10        5.149 %      0.185 %                0.134 %
de_11_20      11698      14        8.055 %      0.259 %                 0.12 %
de_21_30      31310      36        21.56 %      0.667 %                0.115 %
de_31_40      33042     136       22.752 %      2.519 %                0.412 %
de_41_50      25610     292       17.635 %      5.407 %                 1.14 %
de_51_60      17055     566       11.744 %     10.481 %                3.319 %
de_61_70       8501    1042        5.854 %     19.296 %               12.257 %
de_71_80       4738    1378        3.263 %     25.519 %               29.084 %
de_81_90       3443    1364        2.371 %     25.259 %               39.617 %
de_91_100      1249     528         0.86 %      9.778 %               42.274 %
Mayor_100        50      30        0.034 %      0.556 %                   60 %

On the one hand it seems that you dont wish to have any hovering, and yet you define a hovertemplate, can you share your thoughts about that? Its not super clear to me what your desired result is...