[英]formatting time axis in rbokeh
I am trying to create a linechart with rbokeh
where the x-axis is supposed to show a datetime variable. 我正在尝试使用
rbokeh
创建一个折线图,其中x轴应该显示一个datetime变量。
Consider the following example: 考虑以下示例:
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))
This produces the following plot: 这将产生以下图:
Not only does this show the wrong values on the x-axis, they are also formatted in a very inconvenient way. 这不仅会在x轴上显示错误的值,而且还会以非常不便的方式格式化它们。 I have tried changing the format to a more appropriate way by using the
format
argument (that has been commented out in my example), but this only causes the plot to not even be created anymore. 我尝试通过使用
format
参数(在我的示例中已注释掉)将格式更改为更合适的方式,但这只会导致不再创建图。
What is going on here? 这里发生了什么?
Your code worked for me with the format argument. 您的代码通过format参数为我工作。 If you want the time included, I would use this:
如果您希望包括时间,我将使用以下方法:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.