以rbokeh格式格式化时间轴
我试图创建一个带有以rbokeh格式格式化时间轴,r,bokeh,rbokeh,R,Bokeh,Rbokeh,我试图创建一个带有rbokeh的折线图,其中x轴应该显示一个日期时间变量 考虑以下示例: data <- tibble( time = as.POSIXct(c("2019-08-27 08:15:00", "2019-08-27 10:30:00", "2019-08-27 12:45:00")), value = c(0.3, 0.6, 0.2) ) figure(data = data) %>% ly_lines(x =
rbokeh
的折线图,其中x轴应该显示一个日期时间变量
考虑以下示例:
data <- tibble(
time = as.POSIXct(c("2019-08-27 08:15:00",
"2019-08-27 10:30:00",
"2019-08-27 12:45:00")),
value = c(0.3, 0.6, 0.2)
)
figure(data = data) %>%
ly_lines(x = time,
y = value) %>%
ly_points(x = time,
y = value,
hover = value) %>%
x_axis(label = "Date"
# number_formatter = "numeral",
# format = list(hours = "%d %B %Y")
) %>%
y_axis(label = "Values",
number_formatter = "numeral",
format = list(percent = "0 %")) %>%
y_range(dat = c(0, 1))
数据%
ly_线(x=时间,
y=值)%>%
ly_点(x=时间,
y=值,
悬停=值)%>%
x_轴(label=“日期”
#数字\u格式化程序=“数字”,
#格式=列表(小时数=“%d%B%Y”)
) %>%
y_轴(label=“value”,
数字\u格式化程序=“数字”,
格式=列表(百分比=“0%”)%%>%
y_范围(dat=c(0,1))
这将生成以下绘图:
这不仅在x轴上显示错误的值,而且它们的格式也非常不方便。
我尝试使用format
参数(在我的示例中已注释掉)将格式更改为更合适的方式,但这只会导致不再创建绘图
这里发生了什么事?您的代码对我来说使用了format参数。如果您希望包括时间,我将使用以下方法:
figure(data = data) %>%
ly_lines(x = time,
y = value) %>%
ly_points(x = time,
y = value,
hover = value) %>%
x_axis(label = "Date",
number_formatter = "numeral",
format = list(hours = "%Y-%m-%d %H:%M:%S")
) %>%
y_axis(label = "Values",
number_formatter = "numeral",
format = list(percent = "0 %")) %>%
y_range(dat = c(0, 1)) %>%
theme_axis("x", major_label_orientation = 45)
奇怪的是,我只是再次检查,如果我删除哈希以禁用注释,代码将不会执行。您是否在label=“Date”之后添加逗号?