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")
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'
.
A possibile solution is to manually set hoverinfo
to 'text'
:
pltyobj <- plotly_build(p)
pltyobj$x$data[[1]]$hoverinfo <- "text"
pltyobj
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments