# 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))
))
Run the code above in your browser using DataLab