我想用Highcharter添加注解。我可以用“经典”散点图来做:
library(highcharter)
df <- data.frame(
x = 1:10,
y = 1:10
)
hchart(df,"line", hcaes(x = x, y = y)) %>%
hc_annotations(
list(
labels = lapply(1:nrow(df),function(i){
list(point = list(x = df$x[i],y = df$y[i],xAxis = 0,yAxis = 0))
})
)
)
问题是,我想在X轴是日期轴时执行此操作,但不知何故,我无法使其正常工作
df <- data.frame(
x = seq(as.Date("2021-01-01"),as.Date("2021-01-10"),by = "days"),
y = 1:10
)
hchart(df,"line", hcaes(x = x, y = y)) %>%
hc_annotations(
list(
labels = lapply(1:nrow(df),function(i){
list(point = list(x = df$x[i],y = df$y[i],xAxis = 0,yAxis = 0))
})
)
)
1条答案
按热度按时间5vf7fwbs1#
Highcharter喜欢使用时间戳来表示日期。尝试使用
datetime_to_timestamp
函数,并将text
与point
沿着包含在列表中。