guide_axis_logticks: Axis guide with ticks for logarithmic breaks

Description Usage Arguments Details Value See Also Examples

View source: R/guide_axis_logticks.R

Description

This axis guide is probably best described as annotation_logticks but implemented as a guide instead of a geom. The tick marks probably best suit log10 transformations.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
guide_axis_logticks(
  title = waiver(),
  check.overlap = FALSE,
  angle = NULL,
  n.dodge = 1,
  order = 0,
  position = waiver(),
  prescaled = FALSE,
  trunc_lower = NULL,
  trunc_upper = NULL,
  base = waiver()
)

Arguments

title

A character string or expression indicating a title of guide. If NULL, the title is not shown. By default (waiver()), the name of the scale object or the name specified in labs() is used for the title.

check.overlap

silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels.

angle

Compared to setting the angle in theme() / element_text(), this also uses some heuristics to automatically pick the hjust and vjust that you probably want.

n.dodge

The number of rows (for vertical axes) or columns (for horizontal axes) that should be used to render the labels. This is useful for displaying labels that would otherwise overlap.

order

Used to determine the order of the guides (left-to-right, top-to-bottom), if more than one guide must be drawn at the same location.

position

Where this guide should be drawn: one of top, bottom, left, or right.

prescaled

A logical of length one, indicating wether the data has been manually rescaled (TRUE) or the scale takes care of the transformation (FALSE).

trunc_lower

The lower and upper range of the truncated axis:

  • NULL to not perform any truncation.

  • A function that takes the break positions as input and returns the lower or upper boundary. Note that also for discrete scales, positions are the mapped positions as numeric.

  • A numeric value in data units for the lower and upper boundaries.

  • A unit object.

trunc_upper

The lower and upper range of the truncated axis:

  • NULL to not perform any truncation.

  • A function that takes the break positions as input and returns the lower or upper boundary. Note that also for discrete scales, positions are the mapped positions as numeric.

  • A numeric value in data units for the lower and upper boundaries.

  • A unit object.

base

When this is provided, the guide takes this as the base for the log transformation instead of trying to guess the base. It is recommended to use this argument if the base is not 10.

Details

The length of minor ticks can be controlled relative to the length of major ticks by setting ggh4x.axis.ticks.length.minor as a rel object. Likewise the size of the smallest ticks are controlled by the ggh4x.axis.ticks.length.minor, also relative to the major ticks.

Value

An axis_logticks guide class object.

See Also

Other axis-guides: guide_axis_minor(), guide_axis_nested(), guide_axis_truncated()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# The guide works well out of the box with log10 scales
p <- ggplot(pressure, aes(temperature, pressure)) +
  geom_line()
p + scale_y_log10(guide = "axis_logticks")

# If the data is already transformed, you can set 'prescaled' to TRUE
ggplot(pressure, aes(temperature, log10(pressure))) +
  geom_line() +
  guides(y = guide_axis_logticks(prescaled = TRUE))

# The lenghts of the log-ticks are controlled by the theme relative to the
# major ticks.
p + scale_y_log10(guide = "axis_logticks") +
  theme(
    axis.ticks.length.y = unit(1, "cm"),
    ggh4x.axis.ticks.length.minor = rel(0.55),
    ggh4x.axis.ticks.length.mini = rel(0.1)
  )

ggh4x documentation built on Feb. 11, 2021, 5:05 p.m.