scale_length: Position scales for length or distance data

Description Usage Arguments Details See Also Examples

Description

This scale allow for easy labeling of data in distance measurements. The scale has two major arguments, 'base' and 'system'. 'system' determine the measurement system, currently "imperial" and "metric" is implemented. For 'base' please refer to details.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
scale_x_length(name = waiver(), breaks = waiver(),
  minor_breaks = waiver(), labels = waiver(), limits = NULL,
  expand = waiver(), oob = censor, na.value = NA_real_,
  position = "bottom", sec.axis = waiver(), base = "metre",
  system = "metric", ignore = NULL)

scale_y_length(name = waiver(), breaks = waiver(),
  minor_breaks = waiver(), labels = waiver(), limits = NULL,
  expand = waiver(), oob = censor, na.value = NA_real_,
  position = "left", sec.axis = waiver(), base = "metre",
  system = "metric", ignore = NULL)

Arguments

name

The name of the scale. Used as the axis or legend title. If waiver(), the default, the name of the scale is taken from the first mapping used for that aesthetic. If NULL, the legend title will be omitted.

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

minor_breaks

One of:

  • NULL for no minor breaks

  • waiver() for the default breaks (one minor break between each major break)

  • A numeric vector of positions

  • A function that given the limits returns a vector of minor breaks.

labels

One of:

  • NULL for no labels

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

  • A character vector giving labels (must be same length as breaks)

  • A function that takes the breaks as input and returns labels as output

limits

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

expand

Vector of range expansion constants used to add some padding around the data, to ensure that they are placed some distance away from the axes. Use the convenience function expand_scale() to generate the values for the expand argument. The defaults are to expand the scale by 5% on each side for continuous variables, and by 0.6 units on each side for discrete variables.

oob

Function that handles limits outside of the scale limits (out of bounds). The default replaces out of bounds values with NA.

na.value

Missing values will be replaced with this value.

position

The position of the axis. "left" or "right" for vertical scales, "top" or "bottom" for horizontal scales

sec.axis

specify a secondary axis

base

Character, dertermine what the base unit is, defaults to "metre".

system

Character, dertermine what measurement system to use is, defaults to "metric".

ignore

Character, which units to ignore.

Details

For "metric", base must be one of

And for "imperial", base must be one of

See Also

Other position scales: scale_x_mass

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
library(ggplot2)
set.seed(1)
df <- data.frame(
  x = 1:100,
  y = cumsum(rnorm(100)) * 100
)

base <- ggplot(df, aes(x, y)) +
  geom_line()

# Will default to grams
base +
  scale_y_length()

# Different baseline unit can be set with `base` argument
base +
  scale_y_length(base = "millimetre")

# Imperial system also implemented
base +
  scale_y_length(base = "inch", system = "imperial")

# Transformation between systems can be done on the fly. First element
# of system denotes the system you are moving from, and the second element
# denotes the system you are moving to.
base +
  scale_y_length(base = "millimetre", system = c("metric", "imperial"))

EmilHvitfeldt/unitscales documentation built on June 13, 2019, 7:46 a.m.