0

Consider the following:

temp <- c("13:30", "09:30", "09:30", "10:00", "13:30", "13:10", "10:00", "13:30", 
          "10:00", "13:30", "13:30", "10:00", "09:30", "13:30", "13:00", "14:00", 
          "09:00", "15:00", "12:00", "13:00", "13:00", "09:00", "09:00", "09:30", 
          "13:00", "13:00", "13:00", "14:00", "09:00", "13:30", "13:00", "13:30", 
          "13:30", "13:30", "13:15", "13:00", "13:30", "14:00", "10:30", "10:00", 
          "14:15", "09:00", "13:30", "13:00", "13:30", "10:30", "13:00", "08:30", 
          "09:00", "09:30", "13:00", "10:00", "10:00", "13:00", "13:30", "09:20", 
          "13:15", "10:30", "14:00", "13:00", "13:00", "13:00", "09:00", "13:30", 
          "13:30", "13:00", "09:30", "09:00", "13:30", "09:30", "13:00", "10:00", 
          "13:00", "13:00", "10:30", "14:45", "13:00", "13:00", "13:00", "13:30", 
          "13:45", "10:00", "13:00", "13:30", "10:15", "13:00", "13:30", "14:00", 
          "09:00", "09:15", "10:30", "14:00")
temp <- strptime(temp, format = "%H:%M")
temp <- as.data.frame(temp)

library(ggplot2)
library(scales)

ggplot(data = temp) + 
  geom_histogram(aes(x = temp), fill = "#228b22", binwidth = 1800, 
                 breaks = seq(min(as.numeric(temp$temp)) - 1800,
                              max(as.numeric(temp$temp)) + 1800, 
                              by = 1800)) + 
  scale_x_datetime(breaks = date_breaks("1 hour"), date_labels = "%r") +
  scale_y_continuous(breaks = seq(from = 0, to = 28, by = 4)) + 
  theme(panel.background = element_rect(fill='white'),
        panel.border=element_rect(fill=NA),
        panel.grid.major=element_line(color="black"),
        panel.grid.minor=element_line(color="black"), 
        axis.text.x = element_text(angle = 90))

The times given above are in military time. As you can see, they fall mainly in the morning-mid afternoon range. Hence this output doesn't make any sense:

enter image description here

Notice the x-axis gives times which are quite late at night, and none in the morning.

Jaap
  • 81,064
  • 34
  • 182
  • 193
Clarinetist
  • 1,097
  • 18
  • 46
  • could it be a question of the time zone when converting to time? temp <- strptime(temp, format = "%H:%M", tz = "UMT") gives a different result then temp <- strptime(temp, format = "%H:%M", tz = "GMT") and again different than temp <- strptime(temp, format = "%H:%M", tz = "") – Ulrik Jul 26 '16 at 17:35
  • @Ulrik That's really bizarre. Hopefully someone here knows the details... – Clarinetist Jul 26 '16 at 18:04
  • Likely a time zone issue, see [here](http://stackoverflow.com/questions/36227130/r-as-posixct-timezone-and-scale-x-datetime-issues-in-my-dataset) and [here](http://stackoverflow.com/a/37737495/2461552) – aosmith Jul 26 '16 at 18:19
  • 1
    Your code gives me the correct output. – Jaap Jul 26 '16 at 18:20
  • Same here - I get the correct output. – elmo Jul 26 '16 at 18:46

0 Answers0