tooltip in ggplot shows data twice

I have a plot in which I added the desired tooltip. But in addition to new labels, it shows default labels (the name of original variables, I mean the first and second lines).
How can I remove the default labels? please see the attached image and the code:
</>

  plot2 = ggplot(f2, aes(x = input$celltype2, y = V1, text = paste("Cell type:", input$celltype2, 
                                                                   "\n", "shap value:", V1))) + 
    geom_jitter(alpha = 0.1, color = "tomato") +
    geom_boxplot(alpha = 0) 
  plot2%>% 
  ggplotly()

</>

the default uses all mapped aesthetics in the tooltip, but you wish it to be only text, therefore:

plot2%>% 
  ggplotly(tooltip="text")

@nirgrahamuk
I tried your comment, but it didn't work, the result is the same.

Your data is private and hasnt been shared with us.
Here is my evidence as to why I expected the solution to work for you

library(tidyverse)
library(plotly)
plot2 = ggplot(iris, aes(x = Petal.Width, y = Petal.Length, text = paste("pw", Petal.Width, 
                                                                 "\n", "pl", Petal.Length))) + 
  geom_jitter(alpha = 0.1, color = "tomato") +
  geom_boxplot(alpha = 0) 

#doesnt work
plot2%>% 
  ggplotly()

#works
plot2%>% 
  ggplotly(tooltip="text")

If you would like further assistance on this matter, I invite you to create a reprex so we can understand the particulars of your case.

Actually, this is my code, I have to separate plots (plot1 and plot2), then by "subplot" I merged them.

</>

f1 = da_cell_plot1()
plot1 = ggplot(f1, aes(x = input$celltype1, y = V1, text = paste("Cell type:", input$celltype1,
"\n", "shap value:", V1))) +
geom_jitter(alpha = 0.1, color = "tomato")+
geom_boxplot(alpha = 0)
plot1%>%
ggplotly(tooltip="text")

  f2 = da_cell_plot2()
  plot2 = ggplot(f2, aes(x = input$celltype2, y = V1, text = paste("Cell type:", input$celltype2, 
                                                                   "\n", "shap value:", V1))) + 
    geom_jitter(alpha = 0.1, color = "tomato") +
    geom_boxplot(alpha = 0) 
  plot2%>% 
  ggplotly(tooltip="text")
  
  Final_fig_box <- subplot(plot1, plot2)%>%
    layout(title = "Inferred Celltype Activity")
  print("it works")
  return(Final_fig_box) 

</>

I cant run your code as it is not a reprex,... but I do se a problem in that when you apply ggplotly() you dont assign the result back to any name, so it wont have an effect beyond showing that plot in the viewer.

  plot2 <- plot2%>% 
  ggplotly(tooltip="text")
1 Like

@nirgrahamuk That's right. Thank you.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.