This guide draws the axis only as wide as the outermost tick marks, similar to offset axes from Prism.

guide_prism_offset(
  title = waiver(),
  check.overlap = FALSE,
  angle = NULL,
  n.dodge = 1,
  order = 0,
  position = 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. Can be one of the following:

  • NULL to take the angles and hjust/vjust directly from the theme.

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

  • A number representing the text angle in degrees.

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

A positive integer of length 1 that specifies the order of this guide among multiple guides. This controls in which order guides are merged if there are multiple guides for the same position. If 0 (default), the order is determined by a secret algorithm.

position

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

Value

Returns a prism_offset guide class object.

Details

Control the length of the axis by adjusting the breaks argument in scale_(x|y)_continuous() or scale_(x|y)_discrete().

Examples

library(ggplot2)

## base plot
base <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  theme(axis.line = element_line(colour = "black"))

## use offset guide via scale_x/y_continuous
base +
  scale_x_continuous(
    limits = c(1, 6),
    breaks = seq(1, 6, by = 1),
    guide = "prism_offset"
  ) +
  scale_y_continuous(
    guide = "prism_offset"
  )


## use offset guide via guides argument
base +
  guides(x = "prism_offset", y = "prism_offset") +
  scale_x_continuous(
    limits = c(1, 6),
    breaks = seq(1, 6, by = 1)
  )


## change colour and tick length with the usual elements
base +
  scale_x_continuous(
    limits = c(0, 6),
    minor_breaks = seq(0, 6, 0.5),
    guide = "prism_offset"
  ) +
  scale_y_continuous(
    limits = c(10, 35),
    minor_breaks = seq(10, 35, 1.25),
    guide = "prism_offset"
  ) +
  theme(
    axis.ticks.length = unit(10, "pt"),
    axis.ticks = element_line(colour = "red"),
    axis.line = element_line(colour = "blue")
  )