PosixCt 的默认轴格式

发布于 2024-12-29 14:20:50 字数 181 浏览 2 评论 0原文

有没有办法可以更改 POSIXct 标签在使用 plot 时以及它们是数据帧的一部分时的显示方式的默认格式(Date HH:MM 而不仅仅是 HH:MM)?

如果我可以做到这一点而不必每次都发出 axis 命令或将数据帧转换为 xts 对象,那就太好了。

Is there a way I can change the default format for how POSIXct labels appear when using plot and when they are part of a dataframe (Date HH:MM instead of just HH:MM)?

I would be nice if I could do this without having to issue an axis command each time or converting the dataframe to an xts object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千と千尋 2025-01-05 14:20:50

答案是文森特·佐尼肯德 (Vincent Zoonekynd)。
您可以在 plot 函数中使用 format 参数以“%Y-%m-%d %H:%M”格式输出数据。
请看下面的代码:

df <- data.frame(
  ms = c(10485849612, 10477641600, 10561104000, 10562745600),
  value = 1:4
)

df$posix_time <- as.POSIXct(df$ms, origin = "1582-10-14", tz = "GMT")
plot(df$posix_time, df$value, format = "%Y-%m-%d %H:%M")

输出:
输出posix_ct 带小时和分钟

Answer goes to Vincent Zoonekynd.
You can use format argument in plot function to output the data in "%Y-%m-%d %H:%M" format.
Please see the code below:

df <- data.frame(
  ms = c(10485849612, 10477641600, 10561104000, 10562745600),
  value = 1:4
)

df$posix_time <- as.POSIXct(df$ms, origin = "1582-10-14", tz = "GMT")
plot(df$posix_time, df$value, format = "%Y-%m-%d %H:%M")

Output:
output for posix_ct w/hours and minutes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文