What default breaks algorithm does scale_x_time use?

The ggplot2 default looks nice. I can't see what function they use in the breaks argument as a default?? Thanks :slight_smile:

library(tidyverse)
#> Warning: package 'purrr' was built under R version 4.3.1
#> Warning: package 'dplyr' was built under R version 4.3.1
library(nycflights13)
#> Warning: package 'nycflights13' was built under R version 4.3.1

d <- flights |>
  mutate(date = ymd(paste(year, month, day))) |>
  mutate(datetime = ymd_hm(paste(year, month, day, hour, minute))) |>
  mutate(hourminute = hms::hms(hours = hour, minutes = minute)) |>
  slice_head(n = 1000)

p <- d |> 
  ggplot() +
  geom_point(aes(x = hourminute, y = arr_delay))

p
#> Warning: Removed 11 rows containing missing values or values outside the scale range
#> (`geom_point()`).


p +
  scale_x_continuous(trans = "hms", breaks = scales::breaks_pretty())
#> Warning: Removed 11 rows containing missing values or values outside the scale range
#> (`geom_point()`).

Created on 2023-10-03 with reprex v2.0.2

#breaks for hms come from scales::hms_trans
# see your data calculated out : 
scales::hms_trans()$breaks(d$hourminute)
# look at the function : 
scales::hms_trans()$breaks
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.