Skip to contents

This function constructs a ticks guide primitive.

Usage

primitive_ticks(key = NULL, bidi = FALSE, theme = NULL, position = waiver())

Arguments

key

A standard key specification. See more information in the linked topic.

bidi

A <logical[1]>: whether ticks should be drawn bidirectionally (TRUE) or in a single direction (FALSE, default).

theme

A <theme> object to style the guide individually or differently from the plot's theme settings. The theme argument in the guide overrides and is combined with the plot's theme.

position

A <character[1]> giving the location of the guide. Can be one of "top", "bottom", "left" or "right".

Value

A PrimitiveTicks primitive guide that can be used inside other guides.

Details

Styling options

Below are the theme options that determine the styling of this guide, which may differ depending on whether the guide is used in an axis or in a legend context.

The ticks can come in three variants: major, minor and minimal. Which variants are drawn depends on the keys: key_minor() draws major and minor ticks, whereas key_log() also has minimal ticks. Each variant has a corresponding length setting.

The possible {position} suffixes mentioned below are x, x.top, x.bottom, y, y.left, y.right. The theta and r position suffixes in ggplot2 are not obeyed in legendry.

Theme settingContextTypeDescription
axis.ticks.{position}Axiselement_line()Major tick lines
axis.ticks.length.{position}Axisunit()Major tick length
axis.minor.ticks.{position}Axiselement_line()Minor tick lines
axis.minor.ticks.length.{position}Axisunit()Minor tick length
legendry.axis.mini.ticksAxiselement_line()Minimal tick lines
legendry.axis.mini.ticks.lengthAxisunit()Minimal tick length
legend.ticksLegendelement_line()Major tick lines
legend.ticks.lengthLegendunit()Major ticks length
legendry.legend.minor.ticksLegendelement_line()Minor tick lines
legendry.legend.minor.ticks.lengthLegendunit()Minor ticks length
legendry.legend.mini.ticksLegendelement_line()Minimal tick lines
legendry.legend.mini.ticks.lengthLegendunit()Minimal tick length

Styling options per break can be set in the key. The line and prefixed properties are prioritised for the tick lines. These override theme settings.

The context-agnostic alternative to using theme() is to use theme_guide():

primitive_ticks(theme = theme_guide(
  ticks = element_line(),
  ticks.length = unit(5, "mm"),
  minor.ticks = element_line(),
  minor.ticks.length = unit(4, "mm"),
  mini.ticks = element_line(),
  mini.ticks.length = unit(3, "mm")
))

Examples

# A standard plot
p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point()

# Adding as secondary guides
p + guides(x.sec = primitive_ticks(), y.sec = primitive_ticks())