How do I change the hover text in ggplotly?

I'm trying to create a ggplot then convert it to a plotly graph with the ggplotly using this code:

This gives me this plot:

I want to know how to change the hover text so that it read date: .... and price: ....

When I try the solution provided here, I get an empty plot. Thanks for your help in advance.

A simple solution is to name the variables correctly before making the plot, see this example

library(quantmod)
library(tidyverse)
library(plotly)

apple <- getSymbols("AAPL",
                    src = "yahoo",
                    from = "2019-09-20",
                    to = "2020-09-20",
                    auto.assign = FALSE)

p <- apple %>% 
    as.data.frame() %>% 
    rownames_to_column(var = "Date") %>% 
    transmute(Date = as.Date(Date), Price = AAPL.Adjusted) %>% 
    ggplot(aes(Date, Price)) +
    geom_line()

ggplotly(p)

BTW, next time please provide a proper REPRoducible EXample (reprex) illustrating your issue, what you have done (screenshots), although I'm sure well intended, it can be interpreted as rude since you force people willing to help you, to type from an image.

1 Like

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.