label_basepair: Label numbers as basepairs with SI suffix

Description Usage Arguments Details Value Examples

View source: R/labels-format.R

Description

basepair_label() automatically scales and labels numbers with an appropriate SI suffix, e.g. "kb" for values 1e3, "Mb" for 1e6, "Gb" for 1e9.

Usage

1
2
3
4
5
6
7
8
9
label_basepair(
  accuracy = NULL,
  unit = "b",
  sep = NULL,
  labelsmall = FALSE,
  ...
)

basepair_label(x)

Arguments

accuracy

A number to round to. Use (e.g.) 0.01 to show 2 decimal places of precision. If NULL, the default, uses a heuristic that should ensure breaks have the minimum number of digits needed to show the difference between adjacent values.

Applied to rescaled data.

unit

Optional units specifier.

sep

Separator between number and SI unit. Defaults to " " if units is supplied, and "" if not.

labelsmall

A logical wether of not append the suffix to values smaller than 1000 (default: FALSE).

...

Other arguments passed on to base::format().

x

A vector to label. Can either be numeric of inherit from GenomicRanges, in which case takes the start positions to label.

Details

The label_basepair() function is a function factory that returns a labelling function, i.e. a function that takes a vector x and returns a character vector of length(x) giving a label for each input value. The basepair_label() function is the default labeller from label_basepair() for convenience.

Note that these functions don't attempt to format numbers smaller than 1, as the units millibasepair and centibasepairs do not make sense.

When used in combination with scale_(x|y)_genomic, these labelling functions work best as the minor_labels argument.

Value

A function for label_basepair() or a character vector of labels for basepair_label().

Examples

1
2
3
4
5
6
7
8
require(scales)

# The following labels are equivalent
demo_continuous(c(1, 1e9), label = label_basepair())
demo_continuous(c(1, 1e9), label = basepair_label)

# When the label 'bp' is preffered over 'b'
demo_continuous(c(1, 1e9), label = label_basepair(unit = "bp"))

teunbrand/ggnomics documentation built on Aug. 2, 2020, 7:34 p.m.