How do I use the scale_*continuous function with POSIXct class variables?
I aw aware of the the scale_*_datetime functions.
Specifically, I want to understand which trans and labels arguments to use. I cannot see scales::*_trans or scales::label_* functions that relate to datetime POSIXct class??
library(nycflights13)
library(tidyverse)
d <- flights |>
slice_head(n = 1000) |>
mutate(date = ymd(paste(year, month, day))) %>%
mutate(departure = make_datetime(year, month, day, hour, minute))
class(d$departure)
#> [1] "POSIXct" "POSIXt"
p <- d |>
ggplot() +
geom_point(aes(x = departure, y = dep_delay))
p +
scale_x_continuous(
trans = "hms",
labels = scales::label_date_short()
)
#> Warning: Removed 4 rows containing missing values or values outside the scale range
#> (`geom_point()`).
Here is code for the default plotting of the data, which seems to provide nice datetime labels, and an example of using scale_x_continuous(). I would use scale_x_datetime() instead but I guess you have a reason for using the *continuous() scale.
library(nycflights13)
library(tidyverse)
d <- flights |>
slice_head(n = 1000) |>
mutate(date = ymd(paste(year, month, day))) %>%
mutate(departure = make_datetime(year, month, day, hour, minute))
#Defaul ggplot result
p <- d |>
ggplot() +
geom_point(aes(x = departure, y = dep_delay))
p
#> Warning: Removed 4 rows containing missing values (`geom_point()`).