![](/img/trans.png)
[英]Is there a way to not display hover values for add_trace values in R plotly?
[英]R plotlly add_trace issue when x-axis values are POSIXct
我想這可能是更容易為我們在添加參考線plotly
喜歡使用geom_vline
或geom_hline
在ggplot2
甚至abline
在基地R.
我們可以使用add_trace
函數來模仿geom_hline
但是這次似乎我添加了錯誤的x值。
library(plotly)
library(lubridate)
D = data.frame(
y = round(rnorm(10),1),
x = structure(c(1498640394, 1498641854, 1498642201, 1498642515, 1498642749,
1498643011, 1498643247, 1498643499, 1498643735, 1498643992),
tzone = "UTC", class = c("POSIXct", "POSIXt"))
)
D$DATE_TIME = lubridate::ymd_hms(D$x)
MIN = min(D$x)
MAX = max(D$x)
H = 0
plot_ly(D, x = ~x, y = ~ y, type = "scatter", mode ="lines+markers") %>%
add_trace(x = c(MIN, MAX), y = c(H, H), name = "Reference", mode = "lines", line=list(color="red",dash="dash"))
參考線走錯了路。 為什么會這樣?
解決此問題的方法:
MIN = min(D$x) - 28800
MAX = max(D$x) - 28800
那么該圖表目前是正確的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.