1

I have this piece of code. How can I please easy change hover text diff to newlabel ? Here is my site http://webcovid19.online/

 ggplotly(
        ggplot(my_data, aes(x=date, y=diff)) + 
        geom_bar(stat='identity',fill='red')  +
        scale_y_continuous(labels = comma) 
    )
2
  • please check stackoverflow.com/questions/40598011/… Commented Dec 7, 2020 at 12:14
  • yes, I was checking this post already before, but from there is not very clear for me how to do it in my case. Commented Dec 7, 2020 at 12:22

1 Answer 1

2

You can customize the text in the tooltip adding text to your aes() in ggplot. Here, you can include both date and diff with whatever text label you want (or just include diff alone). Within ggplotly, you can include tooltip = "text" to refer to this text with hover.

library(plotly)
library(scales)

ggplotly(
  ggplot(my_data, aes(x=date, y=diff, text = paste("Date:", date, "\nnewlabel:", diff))) + 
    geom_bar(stat='identity', fill='red')  +
    scale_y_continuous(labels = comma),
  tooltip = "text"
)
Sign up to request clarification or add additional context in comments.

4 Comments

muchas gracias Ben
Hi Ben, Is it possible to change text size of hover text ? I found something here via hoverlabel , but not sure how to do it in my case. stackoverflow.com/questions/38076722/…
Hi Andrew - if you save your ggplotly() object as gg, then you can change the style such as: style(gg, hoverlabel = list(font = list(size = 24)))...it is tricky with all the lists involved in this, but it is more clearly described here.
Excellent ! I use this way ...%>% style (hoverlabel = list(font=list(size=20)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.