|
4 | 4 | #' titles to each border of the plot: top, left, bottom, and right.
|
5 | 5 | #'
|
6 | 6 | #' @details
|
7 |
| -#' You can also use [labs()][ggplot2::labs] to specify the titles (use arguments |
8 |
| -#' `r oxford_and(.TLBR)`) for the top, left, bottom, and right borders of the |
9 |
| -#' plot. |
10 | 7 | #'
|
11 | 8 | #' The appearance and alignment of these patch titles can be customized using
|
12 | 9 | #' [theme()][ggplot2::theme]:
|
|
23 | 20 | #'
|
24 | 21 | #' @param top,left,bottom,right A string specifying the title to be added to the
|
25 | 22 | #' top, left, bottom, and right border of the plot.
|
26 |
| -#' @return A [labels][ggplot2::labs] object to be added to ggplot. |
| 23 | +#' @return A [`labels`][ggplot2::labs] object to be added to ggplot. |
27 | 24 | #' @examples
|
28 | 25 | #' ggplot(mtcars) +
|
29 | 26 | #' geom_point(aes(mpg, disp)) +
|
|
37 | 34 | #' @importFrom ggplot2 waiver
|
38 | 35 | patch_titles <- function(top = waiver(), left = waiver(), bottom = waiver(),
|
39 | 36 | right = waiver()) {
|
40 |
| - add_class(ggplot2::labs( |
41 |
| - top = top, left = left, bottom = bottom, right = right |
42 |
| - ), "patch_labels") |
| 37 | + structure( |
| 38 | + list(top = top, left = left, bottom = bottom, right = right), |
| 39 | + class = "ggalign_patch_labels" |
| 40 | + ) |
43 | 41 | }
|
44 | 42 |
|
45 | 43 | #' @importFrom ggplot2 find_panel calc_element zeroGrob element_grob merge_element
|
@@ -173,8 +171,11 @@ setup_patch_titles <- function(table, patch_titles, theme) {
|
173 | 171 |
|
174 | 172 | #' @importFrom ggplot2 ggplot_add
|
175 | 173 | #' @export
|
176 |
| -ggplot_add.patch_labels <- function(object, plot, object_name) { |
177 |
| - plot <- NextMethod() |
| 174 | +ggplot_add.ggalign_patch_labels <- function(object, plot, object_name) { |
| 175 | + plot$ggalign_patch_labels <- update_non_waive( |
| 176 | + .subset2(plot, "ggalign_patch_labels") %||% list(), |
| 177 | + object |
| 178 | + ) |
178 | 179 | if (!inherits(plot, "patch_ggplot")) {
|
179 | 180 | plot <- add_class(plot, "patch_ggplot")
|
180 | 181 | }
|
|
0 commit comments