breaks_divMult | R Documentation |
Compute breaks for ratio scale
breaks_divMult(n = 6, nmin = 5, anchor = TRUE, splits = 5, base = exp(1))
n |
Scalar, target number of breaks |
nmin |
Scalar, forced minimum number of breaks |
anchor |
NULL or scalar, value to include as a reference point (usually 1) |
splits |
Integer, one of |
base |
a positive or complex number: the base with respect to which
logarithms are computed. Defaults to |
Vector of values to generate axis breaks
Other breaking:
limit_breaks()
,
limitimil()
,
split_decades()
y <- exp(seq(-2,5, length.out = 10))
v <- log(y) # log data or data range
n <- 5
# axisTicks takes giant steps, returns values way beyond data
grDevices::axisTicks(nint = n, log = TRUE, usr = range(v))
# breaks_divMult gives ~n breaks evenly within the data
breaks_divMult(n = n)(v = y)
# if 1 is lower limit, only positive log(breaks)
breaks_divMult()(c(1, 11))
# ditto, only negative log(breaks) if 1 is upper limit
breaks_divMult()(c(0.04, 1))
# expanding range on one side of 1 doesn't leave the other side behind
breaks_divMult()(c(0.04, 2.2))
breaks_divMult()(c(0.04, 220))
breaks_divMult()(c(0.04, 2200))
x <- 1:10
dat <- data.frame(x, y)
dat %>% ggplot2::ggplot(ggplot2::aes(x, y))+
ggplot2::geom_point()+
ggplot2::geom_hline(yintercept = 1, linewidth = 0.2) +
ggplot2::scale_y_continuous(
transform = "log"
, breaks = breaks_divMult()
, labels = label_divMult()
)
# custom breaks might still be needed when y-range is small
y2 <- seq(0.68, 2.2, length.out = 10)
dat2 <- data.frame(x, y2)
dat2 %>% ggplot2::ggplot(ggplot2::aes(x, y2))+
ggplot2::geom_point()+
ggplot2::geom_hline(yintercept = 1, linewidth = 0.2) +
ggplot2::scale_y_continuous(
transform = "log"
# , breaks = breaks_divMult()
, breaks = c(seq(0.4, 2.2, by = 0.2))
, labels = label_divMult()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.