R 如何格式化时间序列图的x标签?
这是我的数据框,从这个数据框我绘制时间序列图R 如何格式化时间序列图的x标签?,r,time-series,R,Time Series,这是我的数据框,从这个数据框我绘制时间序列图 data.frame(df3) Time Price 2/21/2018 09:00:00am 122.12 2/21/2018 09:07:38am 122.43 2/21/2018 09:09:10am 122.44 2/21/2018 09:09:10am 122.45 2/21/2018 09:09:21am 122.26 2/21/2018 09:13:16am 122.37 ... 这是时间序列图的编
data.frame(df3)
Time Price
2/21/2018 09:00:00am 122.12
2/21/2018 09:07:38am 122.43
2/21/2018 09:09:10am 122.44
2/21/2018 09:09:10am 122.45
2/21/2018 09:09:21am 122.26
2/21/2018 09:13:16am 122.37
...
这是时间序列图的编码:
ts.plot(df3$Price, gpars=list(xlab="Time", ylab="Price"))
输出为:
我想更改图表上的x标签,我想更改x标签显示的格式“2/21/2018 09:13:16am”
格式
提前感谢“我想要我的x标签显示格式”2018年2月21日09:13:16am“格式”我不知道你的意思。我假设您需要时间序列数据的合理时间点的刻度和标签
我建议使用zoo
# Load sample data
df <- read.table(text =
"Time Price
'2/21/2018 09:00:00am' 122.12
'2/21/2018 09:07:38am' 122.43
'2/21/2018 09:09:10am' 122.44
'2/21/2018 09:09:10am' 122.45
'2/21/2018 09:09:21am' 122.26
'2/21/2018 09:13:16am' 122.37", header = T)
# Convert data.frame to zoo time series object
library(zoo)
Price <- zoo(df$Price, as.POSIXct(df$Time, format = "%m/%d/%Y %I:%M:%S%p"))
# Plot
library(ggplot2)
autoplot(Price) + labs(x = "Time")
#加载样本数据
df您可能需要发布类(df3$Time)
的值。另见这个问题: