I am getting error while plotting x axis scale on ggplot.
lubridate::parse_date_time(df1$hr,"H:M") -> df1$hr
ggplot(data = df1 , aes(x = hr, y = Val, color = Date)) +geom_line() +
scale_x_datetime(date_breaks = "1 hours", date_labels = "%H:%M")
Below is my sample data.
df1 <- data.table::fread("Date hr Val
19/02/19 0:00 1292
19/02/19 1:00 1047
19/02/19 2:00 160
19/02/19 3:00 80
19/02/19 4:00 67
19/02/19 5:00 48
19/02/19 6:00 30
19/02/19 7:00 99
19/02/19 8:00 188
19/02/19 9:00 42
19/02/19 10:00 14
19/02/19 11:00 27
19/02/19 12:00 21
19/02/19 13:00 21
19/02/19 14:00 110
19/02/19 15:00 535
19/02/19 16:00 1503
19/02/19 17:00 2626
19/02/19 18:00 4859
19/02/19 19:00 5699
19/02/19 20:00 5718
19/02/19 21:00 5337
19/02/19 22:00 6101
19/02/19 23:00 5381
20/02/19 0:00 1836
20/02/19 1:00 236
20/02/19 2:00 96
20/02/19 3:00 79
20/02/19 4:00 115
20/02/19 5:00 123
20/02/19 6:00 137
20/02/19 7:00 142
20/02/19 8:00 119
20/02/19 9:00 99
20/02/19 10:00 92
20/02/19 11:00 109
20/02/19 12:00 118
20/02/19 13:00 159
20/02/19 14:00 269
20/02/19 15:00 648
20/02/19 16:00 981
20/02/19 17:00 1371
20/02/19 18:00 1804
20/02/19 19:00 2772
20/02/19 20:00 4582
20/02/19 21:00 5346
20/02/19 22:00 5244
20/02/19 23:00 4956")
what I am trying to do is to plot all hours on x axis scale but getting below error
Error in as.POSIXlt.character(as.character(x), ...) : character string
is not in a standard unambiguous format.
However it works for subset of same data frame.
I think it works when hour is either 1 digit long or two digit long and not both at same time
parse_date_time
- that's not a proper date time format. – markus> df1$hr<-as.POSIXct(df1$hr,format="%H") > ggplot(data = df1 , aes(x = hr, y = Val, color = Date)) +geom_line()+ + scale_x_datetime(date_labels = "%H",date_breaks = "1 hour")
– Aprilian8