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")
You’re right, the hoverinfo=‘text’ seems to be not working with the candlestick. You need to do it like the code below and specify you customer text in the add_markers part.
p <- df %>%
plot_ly(x = ~Date, type="candlestick",
open = ~AAPL.Open, close = ~AAPL.Close,
high = ~AAPL.High, low = ~AAPL.Low,
hoverinfo = 'none'
) %>%
add_markers(y = ~(AAPL.Low + AAPL.High)/2, hoverinfo = "text",
text = ~paste("High: ", round(AAPL.High,4)), marker = list(color = "transparent")) %>%
layout(title = "Basic Candlestick Chart")