View source: R/guide_prism_bracket.R
guide_prism_bracket | R Documentation |
This guide turns the axis into brackets drawn around each axis label.
guide_prism_bracket(
title = waiver(),
check.overlap = FALSE,
angle = NULL,
n.dodge = 1,
order = 0,
position = waiver(),
width = NULL,
outside = TRUE
)
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 |
A positive |
position |
Where this guide should be drawn: one of top, bottom, left, or right. |
width |
|
outside |
|
The number of brackets can be adjusted using the breaks
argument in scale_(x|y)_continuous()
or scale_(x|y)_discrete()
.
Returns a prism_bracket guide class object.
library(ggplot2)
## base plot
base <- ggplot(mpg, aes(x = as.factor(cyl), y = hwy)) +
geom_jitter(width = 0.2) +
theme(axis.line = element_line(colour = "black"))
## use brackets on x axis
# if not specified, the width of the brackets is guessed
base + scale_x_discrete(guide = "prism_bracket")
# you can add brackets using the guide function as well
base + guides(x = "prism_bracket")
## works with coord_flip
base + scale_x_discrete(guide = "prism_bracket") +
coord_flip()
## adjust bracket width
base + scale_x_discrete(guide = guide_prism_bracket(width = 0.12))
## make brackets point inward
base + scale_x_discrete(guide = guide_prism_bracket(width = 0.12, outside = FALSE))
## change colour with the usual axis.line, axis.ticks, axis.text elements
base + scale_x_discrete(guide = guide_prism_bracket(width = 0.12, outside = FALSE)) +
theme(axis.line.x = element_line(colour = "red"),
axis.ticks.x = element_line(colour = "blue"),
axis.text.x = element_text(colour = "green"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.