File: get_titles.R

package info (click to toggle)
r-cran-cowplot 1.1.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,564 kB
  • sloc: sh: 13; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 612 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#' Get plot titles
#'
#' These functions extract just the titles from a ggplot. `get_title()` pulls
#' the title, while `get_subtitle()` pulls the subtitle.
#'
#' @param plot A ggplot or gtable.
#' @examples
#' library(ggplot2)
#'
#' p <- ggplot(mpg, aes(displ, cty)) +
#'   geom_point() +
#'   labs(
#'     title = "Plot title",
#'     subtitle = "Plot subtitle"
#'   )
#' ggdraw(get_title(p))
#' ggdraw(get_subtitle(p))
#'
#' @export
get_title <- function(plot) {
  get_plot_component(plot, "^title")
}

#' @rdname get_title
#' @export
get_subtitle <- function(plot) {
  get_plot_component(plot, "subtitle")
}