Why when I run the same code with different data but the same size and time do I always get different thickness of candles? This is not normal, but I don’t understand what’s wrong.
Try running this code several times
library(xts)
tm <- Sys.time()+1:2000
p1 <- rnorm(2000) |> cumsum() |> xts(tm) |> to.minutes(name = NULL)
library(plotly)
df1 <- data.frame(Date=index(p1),coredata(p1))
fig <- df1 %>%
plot_ly(x = ~Date, type="candlestick",
open = ~Open, close = ~Close,
high = ~High, low = ~Low,
line = list(width = 1),
increasing = list(line = list(color = '#17BECF')),
decreasing = list(line = list(color = '#7F7F6F'))) %>%
layout(title = "Basic Candlestick Chart",
xaxis = list(rangeslider = list(visible = F),showgrid = FALSE),
yaxis = list(showgrid = FALSE),
margin = list(l = 40, r = 0, b = 10, t = 10),
dragmode = "pan",
plot_bgcolor = 'black',
paper_bgcolor = '#000011',
font = list(color = 'gray'),
images = list(
list(
source = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/R_logo.svg/1200px-R_logo.svg.png",
x = 0, y = 1,
sizex = 1, sizey = 1,
xref = "paper", yref = "paper",
opacity = 0.1,
layer = "below"
)
))
fig
How can I fix this and rigidly select the width of the candles so that it never changes?