I do not know of a way to center Time only data on midnight in a ggplot, but as a fairly simple workaround you can convert your times to datetimes, with all times before midnight coded as one day (you can choose any arbitrary day, in the code here I used today), and all times after midnight coded as the next day. You can then make a ggplot with a datetime axis centered on the midnight between those two days, and do some axis label formatting to make it look like a time only axis.
library(tidyverse)
library(hms) #package for handling time data
#Generate date and time data
LBB <- data.frame(RecordingDate =
rep(seq.Date(as.Date("2021-04-01"), as.Date("2021-04-20"),
"days"), 25),
Time = hms(sample(0:59, replace = TRUE, 500),
sample(0:59, replace = TRUE, 500),
sample(c(0:5, 20:23), replace = TRUE, 500)))
# Make a graph.datetime column that assigns all times before midnight to the same
# date, and all times after midnight to the next day (you can choose any day)
LBB <- LBB %>%
mutate(graphing.date = if_else(
Time > parse_hms("12:00:00"), as.Date("2021-10-19"), #times 12 to 24 are this date
as.Date("2021-10-20")), #other times (0-12) are this date
#combine date and time to get a graphing datetime spread over two days
#(now you have data that is centered on midnight)
graphing.datetime = as.POSIXct(paste(graphing.date, Time)))
#Graph, but use recording.datetime, not Time as y variable
p <- ggplot(LBB, aes(x = RecordingDate, y = graphing.datetime)) +
geom_point() +
#format the y axis so it looks like Time even though it is datetime
scale_y_datetime("Time", #change axis title back to time
#Set limits to show a full day
limits = c(as.POSIXct("2021-10-19 12:00:00"),
as.POSIXct("2021-10-20 12:00:00")),
expand = c(0,0), #turn off axis limit expansion
date_breaks = "4 hours", #set custom axis breaks
date_labels = "%H:%M") #Hours:minutes only for labels
p
