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