Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何格式化时间序列图的x标签?_R_Time Series - Fatal编程技术网

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)
的值。另见这个问题: