scale_show_infinites_x: Include Infinite Values in Plot

View source: R/scales.R

scale_show_infinites_xR Documentation

Include Infinite Values in Plot

Description

Will replace infinite values by the nearest limit.

Usage

scale_show_infinites_x(
  trans = "identity",
  limits = NULL,
  position = "bottom",
  breaks = ggplot2::waiver(),
  ...
)

Arguments

trans

For continuous scales, the name of a transformation object or the object itself. Built-in transformations include "asn", "atanh", "boxcox", "date", "exp", "hms", "identity", "log", "log10", "log1p", "log2", "logit", "modulus", "probability", "probit", "pseudo_log", "reciprocal", "reverse", "sqrt" and "time".

A transformation object bundles together a transform, its inverse, and methods for generating breaks and labels. Transformation objects are defined in the scales package, and are called <name>_trans (e.g., scales::boxcox_trans()). You can create your own transformation with scales::trans_new().

limits

One of:

  • NULL to use the default scale range

  • A numeric vector of length two providing limits of the scale. Use NA to refer to the existing minimum or maximum

  • A function that accepts the existing (automatic) limits and returns new limits. Also accepts rlang lambda function notation. Note that setting limits on positional scales will remove data outside of the limits. If the purpose is to zoom, use the limit argument in the coordinate system (see coord_cartesian()).

position

For position scales, The position of the axis. left or right for y axes, top or bottom for x axes.

breaks

One of:

  • NULL for no breaks

  • waiver() for the default breaks computed by the transformation object

  • A numeric vector of positions

  • A function that takes the limits as input and returns breaks as output (e.g., a function returned by scales::extended_breaks()). Also accepts rlang lambda function notation.

...

Other arguments to ggplot2::scale_x_continuous or ggplot2::scale_y_continuous

Details

This function also allows you to pass arguments along to ggplot2::scale_x_continuous() since once you add this call you won't be able to edit the continuous scale elsewhere. Oftentimes you'll want to use the trans argument to, for example, visualize your data on a log scale.

Value

ScaleContinuousPosition object that can be added to a ggplot object using '+'

See Also

scale_show_infinites_y()

ggplot2::scale_x_continuous()

Examples

## Not run: 
data = mtcars
    dplyr::mutate(qsec2 = ifelse(qsec > 19, Inf, qsec))

# Plot with infinites set to nearest limit
data %>%
    ggplot2::ggplot(ggplot2::aes(x=qsec2, y=carb)) +
    ggplot2::geom_point() +
    scale_show_infinites_x()

# Plot on a log10 scale with infinites set to nearest limit
data %>%
    ggplot2::ggplot(ggplot2::aes(x=qsec2, y=carb)) +
    ggplot2::geom_point() +
    scale_show_infinites_x(trans="log10")
 
## End(Not run)

selkamand/utilitybeltgg documentation built on July 14, 2022, 2:32 p.m.