Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let user to add their own class to put into patchwork. #393

Open
Yunuuuu opened this issue Sep 13, 2024 · 3 comments
Open

Let user to add their own class to put into patchwork. #393

Yunuuuu opened this issue Sep 13, 2024 · 3 comments

Comments

@Yunuuuu
Copy link
Contributor

Yunuuuu commented Sep 13, 2024

I have modified the patchwork process to let user add their classes for alignment instead of using is_valid_plot:

if (!all(vapply(plots, is_valid_plot, logical(1)))) cli_abort('Only know how to add {.cls ggplot} and/or {.cls grob} objects')

What the developer should do is to add alignpatch method (If necessary, we can define the detail behaviour with a subclass of Patch which is a ggproto class): https://github.com/Yunuuuu/ggalign/blob/01f6063311313e5dff76e34ea77e92f5e2cffbb1/R/alignpatch-.R#L146

Now, I have added methods for my own classes (two Layout) in ggalign, classes from ComplexHeatmap, and patchwork class.

knitr::opts_knit$set(upload.fun = identity)
library(ggalign)
#> Loading required package: ggplot2
  p1 <- ggplot(mtcars, aes(mpg)) +
    geom_density() +
    facet_wrap(~vs)
  p2 <- ggplot(mtcars, aes(mpg)) +
    geom_density() +
    facet_wrap(~vs)
  align_plots(p1,
    free_vp(p2, y = 0, height = unit(10, "cm"), just = "bottom"),
    ComplexHeatmap::Heatmap(rnorm(100L), column_names_rot = 0),
    patchwork::wrap_plots(p1, p2),
    nrow = 2L
  )

image

Created on 2024-09-14 with reprex v2.1.0
~

@Yunuuuu
Copy link
Contributor Author

Yunuuuu commented Sep 13, 2024

I want to push all these features to pachwork, since ggalign focus on plot which need reorder the axis like dendrogram (we need reorder the data before using patchwork to compose the plot). See the column names of the heatmap (they are reordered to match the dendrogram):

set.seed(123)
small_mat <- matrix(rnorm(81), nrow = 9)
rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat)))
colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat)))
ggheatmap(small_mat) +
  hmanno("t") +
  align_dendro(aes(color = branch), k = 3) +
  geom_point(aes(color = branch, y = y))

@thomasp85
Copy link
Owner

This seems like a duplicate of #193 - I agree this would be useful

@Yunuuuu
Copy link
Contributor Author

Yunuuuu commented Sep 16, 2024

Thanks, that's what I wanted, I missed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants