View source: R/guide-axis-nested.R
guide_axis_nested | R Documentation |
This axis guide gives extra range annotations to position scales. It can be used to infer nesting structure from labels or annotate ranges.
guide_axis_nested(
key = "range_auto",
regular_key = "auto",
type = "bracket",
title = waiver(),
theme = NULL,
angle = waiver(),
cap = "none",
bidi = FALSE,
oob = "squish",
drop_zero = TRUE,
pad_discrete = NULL,
levels_text = NULL,
...,
order = 0,
position = waiver()
)
key |
One of the following:
|
regular_key |
A standard key specification for the appearance of regular tick marks. |
type |
Appearance of ranges, either |
title |
A |
theme |
A |
angle |
A specification for the text angle. Compared to setting the
|
cap |
A method to cap the axes. One of the following:
|
bidi |
A |
oob |
A method for dealing with out-of-bounds (oob) ranges. Can be one
of |
drop_zero |
A |
pad_discrete |
A |
levels_text |
A list of |
... |
Arguments passed on to |
order |
A positive |
position |
A |
Under the hood, this guide is a stack composition of a line, ticks, optionally labels and either bracket, box or fence primitives.
By default, the key = "range_auto"
will incorporate the 0th
level labels inferred from the scale's labels. These labels will look like
regular labels.
To offer other keys the opportunity to display ranges alongside
regular-looking labels, the regular_key
argument can be used to setup a
separate key for display in between the ticks and ranges.
A <Guide>
object.
Other standalone guides:
guide_axis_base()
,
guide_axis_dendro()
,
guide_circles()
,
guide_colbar()
,
guide_colring()
,
guide_colsteps()
,
guide_legend_base()
,
guide_legend_cross()
,
guide_legend_group()
# A plot with nested categories on the x-axis
p <- ggplot(mpg, aes(interaction(drv, cyl), hwy)) +
geom_boxplot()
p + guides(x = "axis_nested")
# Apply styling to brackets
p + guides(x = "axis_nested") +
theme_guide(bracket = element_line("red", linewidth = 1))
# Don't drop nesting indicators that have 0-width
p + guides(x = guide_axis_nested(drop_zero = FALSE))
# Change additional padding for discrete categories
p + guides(x = guide_axis_nested(pad_discrete = 0))
# Change bracket type
p + guides(x = guide_axis_nested(bracket = "curvy"))
# Use boxes instead of brackets + styling of boxes
p + guides(x = guide_axis_nested(type = "box")) +
theme_guide(box = element_rect("limegreen", "forestgreen"))
# Using fences instead of brackets + styling of fences
p + guides(x = guide_axis_nested(type = "fence", rail = "inner")) +
theme_guide(
fence.post = element_line("tomato"),
fence.rail = element_line("dodgerblue")
)
# Use as annotation of a typical axis
# `regular_key` controls display of typical axis
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
guides(x = guide_axis_nested(
key = key_range_manual(start = 2:3, end = 5:6, name = c("First", "Second")),
regular_key = key_manual(c(2, 2.5, 3, 5, 7))
))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.