Is it possible to strip the leading zero from the hour as displayed on the x axis, while using ggplot2's scale_x_datetime?
We can use date_format from scales package:
library(ggplot2)
library(scales)
# dummy data
set.seed(1)
df1 <- data.frame(
x = as.POSIXct(runif(10, 0, 24 * 60 * 60), origin = "2017/04/20"),
y = 1:10
)
# use scales::date_format
ggplot(df, aes(x = x, y = y)) +
geom_point() +
scale_x_datetime(labels = date_format("%l:%M"))
?strptime:
%kThe 24-hour clock time with single digits preceded by a blank.
%lThe 12-hour clock time with single digits preceded by a blank.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With