I have this simple data:
structure(list(ID = 1:2, timing = structure(c(1654641111.14,
1654640774.523), tzone = "CET", class = c("POSIXct", "POSIXt"))), class = "data.frame", row.names = c(NA,
-2L))
ID timing
1 1 2022-06-08 00:31:51.140
2 2 2022-06-08 00:26:14.523
When I plot using ggplot2
, I get this:
ggplot(df_test,
aes(x = ID,
y = timing))
geom_point()
But when I set limits, the graph is empty:
lims <- as.POSIXct(strptime(c("35:00", "25:00"),
format = "%M:%OS",
tz = "CET"))
ggplot(df_test,
aes(x = ID,
y = timing))
geom_point()
scale_y_datetime(limits = lims)
Warning message:
Removed 2 rows containing missing values (geom_point).
I tried to find any solution, but I can't figure out why the limits remove all my values. Does anyone have a solution?
Thanks a lot!
CodePudding user response:
This is simply due to your limits being round the wrong way (they should be earliest, latest whereas you have latest, earliest).
So you can do:
ggplot(df_test,
aes(x = ID,
y = timing))
geom_point()
scale_y_datetime(limits = rev(lims))