问题
I want to plot tick data on a minute-basis. My dataframe looks like the following:
> 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
>
Now I want to plot the first 241 entries, with the correct x-axis description. Currently I use a simple 1:241 vector:
plot(c(1:241),df[1:241,4],type="l")
And I get:

When I try
plot(df[1:241,3],df[1:241,4],type="l")
this looks like:

What's wrong here? Thanks!
EDIT:
> 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 ...
>
EDIT2: Data here.
回答1:
You need to convert your variables Date
and Time
with something like strptime
:
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")
来源:https://stackoverflow.com/questions/20723182/plot-of-minute-tick-data-with-correct-x-axis-formatting