Hover text for plotly r candlestick chart

SNT

I am trying to make using of candlestick chart to represent a model output . So I am trying to plot the actual,modeled, and upper and lower values using a candelstick chart in plotly. As per the given example for plotly r the hover always show open,close,high,low. Could I changed this hover text to custom text. Thank you.

library(plotly)
library(quantmod)

getSymbols("AAPL",src='yahoo')

# basic example of ohlc charts
df <- data.frame(Date=index(AAPL),coredata(AAPL))
df <- tail(df, 30)

p <- df %>%
  plot_ly(x = ~Date, type="candlestick",
          open = ~AAPL.Open, close = ~AAPL.Close,
          high = ~AAPL.High, low = ~AAPL.Low) %>%
  layout(title = "Basic Candlestick Chart")
Marco Sandri

This is an interesting question.
Here I try to customize the hover text of the candlestick chart using the following code:

p <- df %>%
  plot_ly(x = ~Date, type="candlestick",
          open = ~AAPL.Open, close = ~AAPL.Close,
          high = ~AAPL.High, low = ~AAPL.Low,
          text = paste("Text1:",df$AAPL.Open,"<br>Text2:",df$AAPL.Close),
          hoverinfo='text') %>%
  layout(title = "Basic Candlestick Chart")

With my plotly_4.8.0.9000 I get a candlestick chart but no hover text appears.
Using plotly_json it is possibile to inspect the JSON sent to plotly.js.
The hoverinfo attribute should be set to 'text' but in data -> 0 -> hoverinfo one can see that it contains an array of strings 'text'.

enter image description here

A possibile solution is to manually set hoverinfo to 'text':

pltyobj <- plotly_build(p)
pltyobj$x$data[[1]]$hoverinfo <- "text"
pltyobj

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Candlestick chart does not show with plotly

R: formatting plotly hover text

Plotly: How to add volume to a candlestick chart?

R plotly: Customize Hover (Info and Text)

R plotly hover label text alignment

How to customize hover text for plotly boxplots in R

Remove auxiliary hover text in plotly R package

Plotly js chart hover text not displaying correct number values

Sorting Plotly bar chart data overlaid on candlestick chart

Plotly adding second bar chart to candlestick chart but get error message

Plotly hover data and hover text

hover text issue in plotly

Plotly hover text not displaying

Is it possible to disable the zoom/pan window on a plotly.py candlestick chart?

display number on top or bottom of a candlestick chart with plotly or other charting libraries

Custom hoverinfo text on plotly R chart that is different to the 'text' parameter?

How to colour part of ggplotly/plotly hover text a different colour in R

Grouping hover text of multiple line with different mode in plotly R

R Plotly how to use both position dodge and format hover text

How to round percantage in hover text with plotly-r

Plotly and ggplot2 hover text in barplot from R not working

R web scraping plotly trace hover text without selenium or phantomjs

Is there a way to add text to the `y2` axis of a plotly chart in R?

Set text size within marker in r plotly bubble chart

How to add text label to R plotly aggregate chart?

Customize hover text for plotly heatmap

Plotly: Unreadable text in hover info

Disable hover text in plotly with ggplot

R: Plotly 'candlestick' objects don't have these attributes