Skip to content

Commit

Permalink
add support for ggsave function
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jul 17, 2024
1 parent 9136a3a commit 17256ff
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ S3method(ggheatmap_add,data.frame)
S3method(ggheatmap_add,default)
S3method(ggheatmap_add,list)
S3method(ggplot_build,ggheatmap)
S3method(grid.draw,ggheat)
S3method(heatmap_add,CoordFlip)
S3method(heatmap_add,default)
S3method(heatmap_add,facetted_pos_scales)
Expand Down Expand Up @@ -86,6 +87,7 @@ importFrom(ggplot2,ggplot_build)
importFrom(ggplot2,is.ggplot)
importFrom(ggplot2,waiver)
importFrom(grid,gpar)
importFrom(grid,grid.draw)
importFrom(grid,is.unit)
importFrom(grid,unit)
importFrom(grid,unit.c)
Expand Down
14 changes: 12 additions & 2 deletions R/ggheat.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,23 @@ methods::setClass(

#' Subset a `ggheatmap` object
#'
#' Used by [ggplot_build][ggplot2::ggplot_build]
#' Used by [ggplot_build][ggplot2::ggplot_build] and [ggsave][ggplot2::ggsave]
#'
#' @param x A ggheatmap object
#' @param name A string of slot name in `ggheatmap` object.
#' @keywords internal
methods::setMethod("$", "ggheatmap", function(x, name) {
slot(x, name)
# https://github.com/tidyverse/ggplot2/issues/6002
if (name == "theme") {
slot(x, "heatmap")$theme
} else if (name == "plot_env") {
slot(x, "plot_env")
} else {
cli::cli_abort(c(
"`$` is just for internal usage for ggplot2 methods",
i = "try to use `@` method instead"
))
}
})

#' @importFrom ggplot2 is.ggplot
Expand Down
6 changes: 6 additions & 0 deletions R/plot-build.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ print.ggheatmap <- function(x, ...) {
print(p)
}

#' @importFrom grid grid.draw
#' @exportS3Method
grid.draw.ggheat <- function(x, ...) {
print(x, ...)
}

#' @importFrom ggplot2 ggplot_build
#' @export
ggplot_build.ggheatmap <- function(plot) {
Expand Down
2 changes: 1 addition & 1 deletion man/cash-ggheatmap-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 17256ff

Please sign in to comment.