如何将日期范围用于 highcharter columnrange plot?
How to use date range for highcharter columnrange plot?
我正在尝试使用 Highcharter 创建一个列范围图,其中的列表示日期范围。虽然这适用于整数,但不适用于日期。其他绘图类型似乎可以很好地处理日期。
以天气df为例:
weather2 <- weather %>%
filter(date < mdy("03-31-2014"))%>%
mutate(low = date, high=date+30, id = row_number()) %>%
select(id, low, high)
hchart(weather2,
type = "columnrange",
hcaes(x = id, high=high, low=low))
绘图呈现为空白,只有 x 轴标签。
但是,如果我只是将日期转换为整数,它会按预期显示一个范围。
weather3 <- weather %>%
filter(date < mdy("03-31-2014"))%>%
mutate(low = as.integer(date), high=as.integer(date+30), id = row_number()) %>%
select(id, low, high)
hchart(weather2,
type = "columnrange",
hcaes(x = id, high=high, low=low))
我也试过添加 %>% hc_yAxis(type = "datetime")
,但这也无济于事。
谢谢!
columnrange 绘图类型似乎要求日期采用时间戳格式。可以使用highcharter中的datetime_to_timestamp
函数进行转换,然后使用hc_yAxis(type = "datetime")
.
weather2 <- weather %>%
filter(date < mdy("03-31-2014"))%>%
mutate(low = datetime_to_timestamp(date),
high = datetime_to_timestamp(date+30),
id = row_number()) %>%
select(id, low, high)
hchart(weather2,
type = "columnrange",
hcaes(x = id, high=high, low=low)) %>%
hc_yAxis(type = "datetime")
我正在尝试使用 Highcharter 创建一个列范围图,其中的列表示日期范围。虽然这适用于整数,但不适用于日期。其他绘图类型似乎可以很好地处理日期。
以天气df为例:
weather2 <- weather %>%
filter(date < mdy("03-31-2014"))%>%
mutate(low = date, high=date+30, id = row_number()) %>%
select(id, low, high)
hchart(weather2,
type = "columnrange",
hcaes(x = id, high=high, low=low))
绘图呈现为空白,只有 x 轴标签。
但是,如果我只是将日期转换为整数,它会按预期显示一个范围。
weather3 <- weather %>%
filter(date < mdy("03-31-2014"))%>%
mutate(low = as.integer(date), high=as.integer(date+30), id = row_number()) %>%
select(id, low, high)
hchart(weather2,
type = "columnrange",
hcaes(x = id, high=high, low=low))
我也试过添加 %>% hc_yAxis(type = "datetime")
,但这也无济于事。
谢谢!
columnrange 绘图类型似乎要求日期采用时间戳格式。可以使用highcharter中的datetime_to_timestamp
函数进行转换,然后使用hc_yAxis(type = "datetime")
.
weather2 <- weather %>%
filter(date < mdy("03-31-2014"))%>%
mutate(low = datetime_to_timestamp(date),
high = datetime_to_timestamp(date+30),
id = row_number()) %>%
select(id, low, high)
hchart(weather2,
type = "columnrange",
hcaes(x = id, high=high, low=low)) %>%
hc_yAxis(type = "datetime")