get_breaks: Create nice axis breaks for plots

View source: R/plot-utils.R

get_breaksR Documentation

Create nice axis breaks for plots

Description

Set the breaks for a graph in nice positions.

Usage

get_breaks(
  limits,
  N = 10,
  max_breaks = 10,
  int_only = TRUE,
  multiples_only = FALSE,
  include_bounds = TRUE
)

ggplot_breaks(...)

Arguments

limits

axis limits. May be either a vector of 2 elements with lower and upper bounds, or a single number (which is the upper bound, the lower bound is then assumed to be 0).

N

step size. The eventual intervals will be multiples of the divisors of N or multiples of N when multiples_only is TRUE. Defaults to 10.

max_breaks

maximum amount of breaks, defaults to 10.

int_only

whether only integer divisors of N may be used as breaks, defaults to TRUE.

multiples_only

whether only multiples of N can be used as breaks, defaults to FALSE.

include_bounds

whether the resulting breaks should encompass min and max. Defaults to TRUE.

...

Arguments passed on to get_breaks

Details

get_breaks is the base function and creates a vector of breaks ggplot_breaks is a wrapper and makes usage easier in ggplot2. The limits of the axis may not be known beforehand, but ggplot_breaks receives it from ggplot and then creates nice breaks.

Value

A sorted numerical vector with breaks of length |max_breaks|+2 when include_bounds is TRUE and of size |max_breaks| otherwise.

Examples

get_breaks(24, N=12, max_breaks=15)

## Not run: 
ggplot() + scale_x_continuous(breaks = ggplot_breaks(N=12, max_breaks=15))
## End(Not run)


hgutils documentation built on March 31, 2022, 5:06 p.m.