View source: R/guide_axis_nested.R
guide_axis_nested | R Documentation |
Discrete position scales containing interacting factors can be visualised more clearly with a nested axis guide. Nested axis guides separate labels based on a delimiter and groups identical later labels, indicating the grouping with a line spanning the earlier labels. The function is questioned due to a possible migration of guide functions after ggplot2 releases a new guide system.
guide_axis_nested(
title = waiver(),
check.overlap = FALSE,
angle = NULL,
n.dodge = 1,
order = 0,
position = waiver(),
delim = waiver(),
inv = FALSE,
trunc_lower = NULL,
trunc_upper = NULL,
colour = NULL,
color = NULL,
extend = 0.5
)
title |
A character string or expression indicating a title of guide.
If |
check.overlap |
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels. |
angle |
Compared to setting the angle in |
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. |
delim |
A |
inv |
A |
trunc_lower , trunc_upper |
The lower and upper range of the truncated axis:
|
colour , color |
A |
extend |
A |
The guide itself makes no effort to group and order labels. To get nice groupings, consider re-ordering the levels of factor variables, or try setting the 'breaks' argument of a scale appropriately.
A axis_nested guide class object.
This axis guide uses the following the theme elements:
ggh4x.axis.nestline.x/y
An element_line()
object to alter the display of the line
separating different layers of labels.
ggh4x.axis.nesttext.x/y
An element_text()
object to differentiate text higher up in the
hierarchy, from the text closest to the axis line.
ggplot2::guide_axis()
for the classic axis
documentation.
weave_factors()
for an alternative to
interaction()
.
Other axis-guides:
guide_axis_logticks()
,
guide_axis_manual()
,
guide_axis_minor()
,
guide_axis_scalebar()
,
guide_axis_truncated()
# The defaults are suited for interaction variables
ggplot(mpg, aes(interaction(cyl, class), hwy)) +
geom_boxplot() +
scale_x_discrete(guide = "axis_nested")
# Control where labels are cut with the delim argument
ggplot(mpg, aes(interaction(cyl, class, sep = "~!~"), hwy)) +
geom_boxplot() +
scale_x_discrete(guide = guide_axis_nested(delim = "!"))
# The nesting lines inherit looks from axis ticks
ggplot(mpg, aes(interaction(cyl, class), hwy)) +
geom_boxplot() +
scale_x_discrete(guide = "axis_nested") +
theme(axis.ticks = element_line(colour = "red"))
# The looks can be controlled independently by setting `ggh4x.axis.nestline`
ggplot(mpg, aes(interaction(cyl, class), hwy)) +
geom_boxplot() +
scale_x_discrete(guide = "axis_nested") +
theme(ggh4x.axis.nestline = element_line(linetype = 2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.