Description Usage Arguments Value Examples
This is a wrapper around cowplot::draw_label()
that creates a ggplot
-based label that inherits formatting from a given theme element. It's more or less been superceded by ggplot
's new plot.title.position
theme argument.
1 | themed_label(label, theme = NULL, element = "text", x = 0.01, hjust = 0, ...)
|
label |
A string of text for label. |
theme |
A ggplot theme; if |
element |
Name of a theme element; defaults to base text. |
x |
x-position; defaults to 0.01 |
hjust |
Horizontal alignment; defaults 0 |
... |
Any other arguments to pass to |
A ggplot
object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ## Not run:
if (requireNamespace("ggplot2", quietly = TRUE)) {
town_pops <- race_pops %>%
dplyr::filter(variable == "total") %>%
dplyr::mutate(name = forcats::fct_reorder(as.factor(name), estimate))
library(ggplot2)
p <- ggplot(town_pops, aes(x = name, y = estimate)) +
geom_col() +
coord_flip()
# With long labels on the left, ggplot's default title placement
# aligned to the panel can become awkward
p + ggtitle("Total population by town, 2017")
# Instead, make a label grob and arrange plot elements how you want
title <- themed_label("Total population by town, 2017", element = "plot.title")
cowplot::plot_grid(
title,
p,
ncol = 1,
rel_heights = c(1, 10)
)
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.