gpt4 book ai didi

带有 x 时间轴 : how to force the ticks labels to be the days? 的 R 图

转载 作者:行者123 更新时间:2023-12-04 00:11:53 25 4
gpt4 key购买 nike

我有这个 csv 格式的文件:

timestamp,pages
2011-12-09T11:20:50.33,4
2012-01-23T17:44:02.71,132
2012-01-28T15:07:59.34,168

第一列是时间戳,第二列是页数。
我需要在垂直轴上绘制页数,在水平轴上绘制时间戳。

时间戳不是固定间隔的,我在 12 月有一天,而在 1 月有两天关闭。

我试过这个代码
df = read.csv("my_data.csv")
df$timestamp = strptime(df$timestamp, "%Y-%m-%dT%H:%M:%S")
plot(df$timestamp,df$pages)

我得到了一个图,在 x 轴的中间只有一个刻度,标签为“Jan”:这没有错,但我想要三个刻度,只有日期和月份。

我试过
plot(df$timestamp,df$pages,xaxt="n")
axis.Date(1,df$timestamp,"days")

但没有绘制 x 轴。
任何的想法?
谢谢

最佳答案

我会as.Date()您的 timestamp像这样:

df$timestamp = as.Date(strptime(df$timestamp, "%Y-%m-%dT%H:%M:%S"))

这将起作用:
plot(df$timestamp,df$pages,xaxt="n")
axis.Date(1,at=df$timestamp,labels=format(df$timestamp,"%b-%d"),las=2)

enter image description here

关于带有 x 时间轴 : how to force the ticks labels to be the days? 的 R 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9053437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com