sub_units: Place Units Under Label

View source: R/sub_units.R

sub_unitsR Documentation

Place Units Under Label

Description

Places units attribute below label attribute. Makes the most sense for figures (style = 'plotmath') and useful for tables (style = 'latex') in combination with alias. See also append_units.

Usage

sub_units(
  x,
  ...,
  open = if (style == "plain") "\n(" else "\\n(",
  close = ")",
  style = "latex",
  math_open = "",
  math_close = "",
  label_open = "$\\begin{gathered}",
  label_close = "\\end{gathered}$",
  newline = "\\\\"
)

Arguments

x

object

...

passed to append_units

open

character to precede units

close

character to follow units

style

one of 'plain', 'latex', or 'plotmath'

math_open, math_close, label_open, label_close, newline

passed to as_latex.spar if style = 'latex'

Value

see methods for append_units

See Also

Other labels: alias.data.frame(), append_units.data.frame(), append_units.default(), append_units(), drop_title.decorated(), drop_title.default(), drop_title.dvec(), drop_title(), make_title.decorated(), make_title.default(), make_title.dvec(), make_title()

Examples

library(units)
library(magrittr)
library(dplyr)
library(ggplot2)
x <- 1:10
attr(x, 'label') <- 'acceleration'
units(x) <- 'm/s^2'
y <- as_units('kg')
x %>% attr('label')
x %>% sub_units %>% attr('label')
x %>% sub_units(style = 'plotmath') %>% attr('label')
x %>% sub_units(style = 'plain') %>% attr('label') %>% writeLines
y %>% attr('label')
y %>% sub_units(style = 'plain') %>% attr('label')
x %>% sub_units(style = 'plotmath')
x %>% sub_units(style = 'latex')

file <- system.file(package = 'yamlet', 'extdata','quinidine.csv')
file %>% decorate %>% resolve %>%
sub_units(style = 'plotmath') %>%
ggplot(data = ., aes(x = time, y = conc, color = Heart)) %>%
add(geom_point())

yamlet documentation built on Oct. 6, 2023, 9:07 a.m.