Skip to content

Commit

Permalink
fix warning for unknown labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jan 8, 2025
1 parent f823679 commit 7e01fc6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ S3method(ggplot_add,ggalign_default_expansion)
S3method(ggplot_add,ggalign_design)
S3method(ggplot_add,ggalign_layer_order)
S3method(ggplot_add,ggalign_no_expansion)
S3method(ggplot_add,ggalign_patch_labels)
S3method(ggplot_add,ggalign_with_quad)
S3method(ggplot_add,patch_inset)
S3method(ggplot_add,patch_labels)
S3method(ggplot_add,theme_recycle)
S3method(ggplot_build,ggalign_heatmap)
S3method(ggupset,"NULL")
Expand Down
10 changes: 1 addition & 9 deletions R/alignpatch-ggplot2.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@ PatchGgplot <- ggproto("PatchGgplot", Patch,
set_theme = function(theme) NULL,
patch_gtable = function(self, plot = self$plot) {
# extract patch titles --------------------------------
patch_titles <- .subset(
.subset2(plot, "labels"),
c("top", "left", "bottom", "right")
)

# we remove patch titles to avoid warning message for unknown labels
plot <- update_labels(plot, list(
top = NULL, left = NULL, bottom = NULL, right = NULL
))
patch_titles <- .subset2(plot, "ggalign_patch_labels")

# complete_theme() will ensure elements exist --------
theme <- complete_theme(.subset2(plot, "theme"))
Expand Down
19 changes: 10 additions & 9 deletions R/alignpatch-title.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#' titles to each border of the plot: top, left, bottom, and right.
#'
#' @details
#' You can also use [labs()][ggplot2::labs] to specify the titles (use arguments
#' `r oxford_and(.TLBR)`) for the top, left, bottom, and right borders of the
#' plot.
#'
#' The appearance and alignment of these patch titles can be customized using
#' [theme()][ggplot2::theme]:
Expand All @@ -23,7 +20,7 @@
#'
#' @param top,left,bottom,right A string specifying the title to be added to the
#' top, left, bottom, and right border of the plot.
#' @return A [labels][ggplot2::labs] object to be added to ggplot.
#' @return A [`labels`][ggplot2::labs] object to be added to ggplot.
#' @examples
#' ggplot(mtcars) +
#' geom_point(aes(mpg, disp)) +
Expand All @@ -37,9 +34,10 @@
#' @importFrom ggplot2 waiver
patch_titles <- function(top = waiver(), left = waiver(), bottom = waiver(),
right = waiver()) {
add_class(ggplot2::labs(
top = top, left = left, bottom = bottom, right = right
), "patch_labels")
structure(
list(top = top, left = left, bottom = bottom, right = right),
class = "ggalign_patch_labels"
)
}

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

#' @importFrom ggplot2 ggplot_add
#' @export
ggplot_add.patch_labels <- function(object, plot, object_name) {
plot <- NextMethod()
ggplot_add.ggalign_patch_labels <- function(object, plot, object_name) {
plot$ggalign_patch_labels <- update_non_waive(
.subset2(plot, "ggalign_patch_labels") %||% list(),
object
)
if (!inherits(plot, "patch_ggplot")) {
plot <- add_class(plot, "patch_ggplot")
}
Expand Down

0 comments on commit 7e01fc6

Please sign in to comment.