R/scale.R

Defines functions scale_y_chron scale_x_chron chron_trans

Documented in chron_trans scale_x_chron scale_y_chron

chron_trans <-
function(format = "%Y-%m-%d", n = 5)
{
    breaks. <- function(x)
        chron(scales::pretty_breaks(n)(x))
    format. <- function(x)
        format(as.POSIXct(x, tz = "GMT"), format = format)
    scales::trans_new("chron",
                      transform = as.numeric, inverse = chron,
                      breaks = breaks., format = format.)
}

scale_x_chron <-
function(..., format = "%Y-%m-%d", n = 5)
{
    ggplot2::scale_x_continuous(..., trans = chron_trans(format, n))
}

scale_y_chron <-
function(..., format = "%Y-%m-%d", n = 5)
{
    ggplot2::scale_y_continuous(..., trans = chron_trans(format, n))
}

Try the chron package in your browser

Any scripts or data that you put into this service are public.

chron documentation built on May 2, 2023, 5:11 p.m.