我想以分钟为基础绘制刻度数据。我的数据框如下所示:
> head(df)
No Date Time Close Volume Weekday
1 3361 03.12.2012 08:00:00.000 7.435 27000000 Montag
2 3362 03.12.2012 08:01:00.000 7.428 47000000 Montag
3 3363 03.12.2012 08:02:00.000 7.428 41000000 Montag
4 3364 03.12.2012 08:03:00.000 7.429 39000000 Montag
5 3365 03.12.2012 08:04:00.000 7.426 44000000 Montag
6 3366 03.12.2012 08:05:00.000 7.423 49000000 Montag
>
现在我想绘制前 241 个条目,并具有正确的 x Axis 描述。目前我使用一个简单的 1:241 矢量:
plot(c(1:241),df[1:241,4],type="l")
我得到:
当我尝试时
plot(df[1:241,3],df[1:241,4],type="l")
这看起来像:
这里出了什么问题?谢谢!
编辑:
> str(df)
'data.frame': 81613 obs. of 6 variables:
$ No : int 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 ...
$ Date : Factor w/ 270 levels "01.01.2013","01.02.2013",..: 25 25 25 25 25 25 25 25 25 25 ...
$ Time : Factor w/ 600 levels "08:00:00.000",..: 1 2 3 4 5 6 7 8 9 10 ...
$ Close : num 7.43 7.43 7.43 7.43 7.43 ...
$ Volume : int 27000000 47000000 41000000 39000000 44000000 49000000 51000000 48000000 49000000 45000000 ...
$ Weekday: Factor w/ 5 levels "Dienstag","Donnerstag",..: 5 5 5 5 5 5 5 5 5 5 ...
>
编辑2: 数据here .
最佳答案
您需要使用 strptime
之类的内容转换变量 Date
和 Time
:
df$DateTime = strptime(paste(as.character(df$Date), as.character(df$Time)), "%m.%d.%Y %H:%M:%S")
plot(df$DateTime[1:241], df$Close[1:241], type="l")
关于r - 具有正确 x Axis 格式的分钟刻度数据图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20723182/