Skip to contents

This function constructs a labels guide primitive.

Usage

primitive_labels(
  key = NULL,
  angle = waiver(),
  n.dodge = 1,
  check.overlap = FALSE,
  theme = NULL,
  position = waiver()
)

Arguments

key

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

angle

A specification for the text angle. Compared to setting the angle argument in element_text(), this argument uses some heuristics to automatically pick the hjust and vjust that you probably want. Can be one of the following:

  • NULL to take angles and justification settings directly from the theme.

  • waiver() to allow reasonable defaults in special cases.

  • A <numeric[1]> between -360 and 360 for the text angle in degrees.

n.dodge

An positive <integer[1]> setting the number of layers text labels can occupy to avoid overlapping labels.

check.overlap

A <logical[1]> indicating whether to check for and omit overlapping text. If TRUE, first, last and middle labels are recursively prioritised in that order. If FALSE, all labels are drawn.

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 <PrimitiveLabels> primitive guide that can be used inside other guides.

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.

As an axis guide

  • axis.text.{x/y}.{position} an <element_text> for the display of the labels.

As a legend guide.

  • legend.text an <element_text> for the display of the labels.

Examples

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

# Adding as secondary guides
p + guides(
  x.sec = primitive_labels(),
  y.sec = primitive_labels(n.dodge = 2)
)