R: Position scales for units data

scale_units {units} | R Documentation

## Position scales for units data

### Description

These are the default scales for the `units` class. These will usually be added automatically. To override manually, use `scale_*_units`.

### Usage

    scale_x_units(..., position = "bottom", unit = NULL)

    scale_y_units(..., unit = NULL)

### Arguments

`...` | arguments passed on to `continuous_scale`.
`position` | For position scales, The position of the axis. `left` or `right` for y axes, `top` or `bottom` for x axes.
`unit` | A unit specification to use for the axis. If given, the values will be converted to this unit before plotting. An error will be thrown if the specified unit is incompatible with the unit of the data.

### Examples

    if (requireNamespace("ggplot2", quietly=TRUE)) {

    library(ggplot2)

    mtcars$consumption <- set_units(mtcars$mpg, mi / gallon)
    mtcars$power <- set_units(mtcars$hp, hp)

    # Use units encoded into the data
    ggplot(mtcars) +
      geom_point(aes(power, consumption))

    # Convert units on the fly during plotting
    ggplot(mtcars) +
      geom_point(aes(power, consumption)) +
      scale_x_units(unit = "W") +
      scale_y_units(unit = "km/l")

    # Resolve units when transforming data
    ggplot(mtcars) +
      geom_point(aes(power, 1 / consumption))

    }

[Package units version 0.8-0 Index]