Ggplot2 and chron barplot temporary data scale_x_chron

I have several times and you want to build the frequency of each time in barplot

library(ggplot2)
library(chron)
test <- data.frame(times = c(rep("7:00:00",4), rep("8:00:00",3), 
                         rep("12:00:00",1), rep("13:00:00",5)))
test$times <- times(test$times)
test
      times
1  07:00:00
2  07:00:00
3  07:00:00
4  07:00:00
5  08:00:00
6  08:00:00
7  08:00:00
8  12:00:00
9  13:00:00
10 13:00:00
11 13:00:00
12 13:00:00
13 13:00:00

The value binwidthis chosen to represent minutes

p <- ggplot(test, aes(x = times)) + geom_bar(binwidth=1/24/60)
p + scale_x_chron(format="%H:%M")

As you can see, scales plus one hour on the x axis:

Link to an example image (Sorry, I do not have enough reputation to publish images)

I have a feeling that this is due to the time zone, but I can not put it:

Sys.timezone()
[1] "CET"

Edit: Thanks @shadow for the comment

UPDATE:

Sys.setenv(TZ='GMT'), . times(). GMT, x, ggplot , CET . , GMT, ggplot .

+4
2

, times(...) , GMT, ggplot . : , . , times(...), ( - , , ).

POSIXct ( EST).

test <- data.frame(times = c(rep("7:00:00",4), rep("8:00:00",3), 
                             rep("12:00:00",1), rep("13:00:00",5)))
test$times <- as.POSIXct(test$times,format="%H:%M:%S",tz="EST")
p <- ggplot(test, aes(x = times)) + geom_bar(binwidth=60,width=.01)

binwidth=60 - 60 .

+4

, , format, %m , %m . ,

p + scale_x_chron(format="%H:%M") 
+2

Source: https://habr.com/ru/post/1531558/


All Articles