Skip to content

is it possible to let ggsave utilize ggplot_build method? #6002

Closed
@Yunuuuu

Description

@Yunuuuu

Hi, is it possible to let ggsave utilize ggplot_build method? in this way, all objects support ggplot_build can use ggsave function

I have developed a ggplot2 extension ggheat for creating heatmaps and I would like to utilize all the functions in ggplot, including ggsave. However, creating a new function with the same name would result in duplication. Additionally, since the package automatically loads ggplot, there is no need to create a duplicate function. Tt would be beneficial to incorporate the ggplot_build method, and it would make ggplot extension more powerful and allow for seamless integration with the existing ggplot function.

library(ggheat)
#> Loading required package: ggplot2
mat <- matrix(rnorm(81), nrow = 9)
rownames(mat) <- paste0("row", seq_len(nrow(mat)))
colnames(mat) <- paste0("column", seq_len(ncol(mat)))
x <- ggheat(mat) +
  scale_fill_viridis_c() +
  htanno_dendro(aes(color = branch), position = "top", k = 3L) +
  gganno_top(aes(y = value), data = rowSums) +
  geom_bar(stat = "identity", aes(fill = factor(.panel))) +
  scale_fill_brewer(name = NULL, palette = "Dark2") +
  gganno_left(aes(x = value), data = rowSums, size = 0.5) +
  geom_bar(
    aes(y = .y, fill = factor(.y)),
    stat = "identity",
    orientation = "y"
  ) +
  scale_x_reverse() +
  htanno_dendro(aes(color = branch),
    position = "left",
    size = unit(1, "null"),
    k = 4L
  ) +
  scale_x_reverse()
ggplot2::ggsave("ggheat.png",
  plot = x,
  width = 350, height = 350, units = "px"
)
#> Error in slot(x, name): no slot of name "theme" for this object of class "ggheatmap"
x

Created on 2024-07-17 with reprex v2.1.0
~

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions