Skip to content

Commit 7e01fc6

Browse files
committed
fix warning for unknown labels
1 parent f823679 commit 7e01fc6

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

Diff for: NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ S3method(ggplot_add,ggalign_default_expansion)
196196
S3method(ggplot_add,ggalign_design)
197197
S3method(ggplot_add,ggalign_layer_order)
198198
S3method(ggplot_add,ggalign_no_expansion)
199+
S3method(ggplot_add,ggalign_patch_labels)
199200
S3method(ggplot_add,ggalign_with_quad)
200201
S3method(ggplot_add,patch_inset)
201-
S3method(ggplot_add,patch_labels)
202202
S3method(ggplot_add,theme_recycle)
203203
S3method(ggplot_build,ggalign_heatmap)
204204
S3method(ggupset,"NULL")

Diff for: R/alignpatch-ggplot2.R

+1-9
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,7 @@ PatchGgplot <- ggproto("PatchGgplot", Patch,
3434
set_theme = function(theme) NULL,
3535
patch_gtable = function(self, plot = self$plot) {
3636
# extract patch titles --------------------------------
37-
patch_titles <- .subset(
38-
.subset2(plot, "labels"),
39-
c("top", "left", "bottom", "right")
40-
)
41-
42-
# we remove patch titles to avoid warning message for unknown labels
43-
plot <- update_labels(plot, list(
44-
top = NULL, left = NULL, bottom = NULL, right = NULL
45-
))
37+
patch_titles <- .subset2(plot, "ggalign_patch_labels")
4638

4739
# complete_theme() will ensure elements exist --------
4840
theme <- complete_theme(.subset2(plot, "theme"))

Diff for: R/alignpatch-title.R

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
#' titles to each border of the plot: top, left, bottom, and right.
55
#'
66
#' @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.
107
#'
118
#' The appearance and alignment of these patch titles can be customized using
129
#' [theme()][ggplot2::theme]:
@@ -23,7 +20,7 @@
2320
#'
2421
#' @param top,left,bottom,right A string specifying the title to be added to the
2522
#' 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.
2724
#' @examples
2825
#' ggplot(mtcars) +
2926
#' geom_point(aes(mpg, disp)) +
@@ -37,9 +34,10 @@
3734
#' @importFrom ggplot2 waiver
3835
patch_titles <- function(top = waiver(), left = waiver(), bottom = waiver(),
3936
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+
)
4341
}
4442

4543
#' @importFrom ggplot2 find_panel calc_element zeroGrob element_grob merge_element
@@ -173,8 +171,11 @@ setup_patch_titles <- function(table, patch_titles, theme) {
173171

174172
#' @importFrom ggplot2 ggplot_add
175173
#' @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+
)
178179
if (!inherits(plot, "patch_ggplot")) {
179180
plot <- add_class(plot, "patch_ggplot")
180181
}

0 commit comments

Comments
 (0)