Nested axis guideSource:
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.
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.
silently remove overlapping labels, (recursively) prioritizing the first, last, and middle labels.
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.
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.
Where this guide should be drawn: one of top, bottom, left, or right.
characterof length 1 to tell
strsplithow hierarchies should be broken up. Internally defaults to
interaction's default delimiter.
TRUE, flips the grouping order. If
FALSE(default), the grouping order is as-is.
- trunc_lower, trunc_upper
The lower and upper range of the truncated axis:
NULLto not perform any truncation.
functionthat takes the break positions as input and returns the lower or upper boundary. Note that also for discrete scales, positions are the mapped positions as
numericvalue in data units for the lower and upper boundaries.
- colour, color
character(1)with a valid colour for colouring the axis text, axis ticks and axis line. Overrules the colour assigned by the theme.
numericof length 1 indicating how much to extend nesting lines relative to the smallest difference in break positions.
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.
This axis guide uses the following the theme elements:
# 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))