r - HighcharteR:情节带和情节线不起作用
问题描述
我正在尝试在 highcharteR 中绘制一个每日价值系列,在图表中标记一条垂直线(情节线)和一段日期(情节带)。我研究了几个 SO question 并找到了这个脚本,但我发现了以下问题:
1) plotband 未绘制 2) ploline 未绘制 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"))
)
)
)
推荐阅读
- c# - 字符串中每个字母后的换行符
- javascript - 获取上传图片的位置
- java - 如何确保用户不能在同一台计算机上做某事
- sql - 将两列数据与第二列的第一个字符组合成一列,留下空值
- reactjs - React - 如何从子功能组件执行功能
- python - 从其他 Python 文件调用函数时的问题
- three.js - glTF 2.0 视频纹理支持
- actions-on-google - 如何获得 Google 的“书面许可”以使用 Google Assistant SDK 将我的项目商业化?
- amadeus - 如何通过 Amadeus Hotel 服务连接客房
- google-bigquery - 使用命令将数据库(具有嵌套文档)从 Cloud Firestore 导出到 Bigquery