First, the question
There was a problem that bothered me for a long time.
I have the following data, the first column is the Hour + minute, the second column is the value:
0000 112
0001 123
0002 122
...
0059 123
0100 120
...
2359 156
How can I draw this into a time sequence diagram of minute granularity? The horizontal axis that is drawn directly using the Ggplot function is a number, not a time.
Second, the answer
The essence of the problem is actually to unify the timescale so that you can convert the time to hourly units or minute units and then the coordinate scale.
1, false with matrix Y:
> y
X x2
[1,] "0000" "0.861078206472926"
[2,] "0001" "-0.0993158925503671"
[3,] "0011" "-0.227230172016484"
[4,] "1201" "0.0763049905510434"
[5,] "1203" "-1.64848265734858"
[6,] "1409" "0.771992874036383"
[7,] "1508" "0.111608655100976"
[8,] "1520" "-1.09952899544323"
X is the hour + minute string variable, and x2 is the value.
2. Time Conversion
(1) Convert to a moment in minutes
> X1b<-round (As.numeric (substr (y[,1],1,2)) + as.numeric (substr (y[1,],3,4))/60,digits=2)
> Plot (X1B,X2)
X1B is the converted time, X2 is the value in the matrix.
(2) The moment of conversion to a unit of hours
> X1c<-as.numeric (substr (y[,1],1,2)) *60 + as.numeric (substr (y[1,],3,4))
> Plot (X1C,X2)
X1C is the converted time, X2 is the value in the matrix.
By drawing contrast, the trend and the law of change are exactly the same, but the units of the time axis are different.
Note: If the observations exceed one day, the day is also converted.
3.
(1) Hours of the unit
(2) Minutes
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
R language-Conversion of time scale