作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 highcharteR 中绘制一个每日值系列,在图表中标记一条垂直线 (plotline) 和一段日期 (plotband)。我研究了几个 SO 问题并找到了这个脚本,但我发现了以下问题:
1) plotband 未绘制2)未绘制的倍数3) xaxis 应该是以我不理解的方式转换日期。
我的可重现代码是:
library(highcharter)
t <- seq(from=as.Date('2017-01-01'), to=as.Date('2018-06-30'), by='days')
d <- runif(n = 546, min = 1, max = 10)
df <- data.frame(t,d)
highchart(type = 'stock')%>%
hc_add_series(name = "Value", type='line', color = "blue",data = df$d) %>%
hc_xAxis(categories = df$t,
type = 'date',
plotLines = list(
list(
label = list(text = "This is a plotLine"),
color = "#FF0000",
width = 5,
value = datetime_to_timestamp(as.Date('2017-01-10', tz = 'UTC'))
)
),
plotBands = list(
list(
label = list(text = "This is a plotBand"),
color = "rgba(100, 0, 0, 0.1)",
from = datetime_to_timestamp(as.Date('2017-02-01', tz = 'UTC')),
to = datetime_to_timestamp(as.Date('2017-02-10', tz = 'UTC'))
)
)
)
获得的输出是:
如有任何帮助/建议,我们将不胜感激!
最佳答案
您可以尝试使用 XTS 包来完成此操作:
library(highcharter)
library(xts)
t <- seq(from = as.Date("2017-01-01"), to = as.Date("2018-06-30"), by = "days")
d <- runif(n = 546, min = 1, max = 10)
df <- data.frame(d)
df <- xts(df, order.by = t)
highchart(type = "stock") %>%
hc_add_series(name = "Value", type = "line", color = "blue", data = df$d) %>%
hc_xAxis(
categories = df$t,
type = "date",
plotLines = list(
list(
label = list(text = "This is a plotLine"),
color = "#FF0000",
width = 5,
value = datetime_to_timestamp(as.Date("2017-01-10", tz = "UTC"))
)
),
plotBands = list(
list(
label = list(text = "This is a plotBand"),
color = "rgba(100, 0, 0, 0.1)",
from = datetime_to_timestamp(as.Date("2017-02-01", tz = "UTC")),
to = datetime_to_timestamp(as.Date("2017-02-10", tz = "UTC"))
)
)
)
关于r - HighcharterR : plotband and plotline not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53195409/
我正在尝试在 highcharteR 中绘制一个每日值系列,在图表中标记一条垂直线 (plotline) 和一段日期 (plotband)。我研究了几个 SO 问题并找到了这个脚本,但我发现了以下问题
我是一名优秀的程序员,十分优秀!