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

Question About Custom Gene Order in ggoncoplot function #47

Open
baishn1289 opened this issue Mar 5, 2025 · 1 comment
Open

Question About Custom Gene Order in ggoncoplot function #47

baishn1289 opened this issue Mar 5, 2025 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@baishn1289
Copy link

baishn1289 commented Mar 5, 2025

Thank you for developing this R package! I am currently using version 0.1.0 and encountered an issue while visualizing a MAF file using ggoncoplot.
I noticed the following behavior:
Setting reorder_row = FALSE sorts genes in ascending order of mutation frequency, whereas reorder_row = TRUE sorts them in descending order.
Setting reorder_col = FALSE orders samples by their names, while reorder_col = TRUE sorts them based on mutation status.
However, ggoncoplot does not seem to provide an option for users to manually specify the order of rows (genes) and columns (samples). Additionally, I attempted to check the vignette using vignette("layout-customize"), but it was unavailable.

Could you please advise if there is a way to manually define the row (gene) and column (sample) order in ggoncoplot?

@Yunuuuu
Copy link
Owner

Yunuuuu commented Mar 5, 2025

Thanks for your patience, and apologies for the outdated documentation! I’m currently updating it. The vignette("layout-customize") you mentioned is now available in the online book at https://yunuuuu.github.io/ggalign-book/layout-customize.html. Note that the book reflects the development version of ggalign (0.1.0.9000), but the solution should work with the released version (0.1.0) as well.

For maftools object, ggoncoplot always uses the gene ordering from the maftools::getGeneSummary if you set reorder_row = FALSE, which already reorder the genes by mutation frequency (From bottom to the top). reorder_row = TRUE reorder the genes by mutation frequency from the top to the bottom (which is what the oncoplot expected).

To manually define the row (gene) and column (sample) order in ggoncoplot, you can use the align_order() function or manually specify the genes argument in ggoncoplot for maftools object. Since I don’t have your data, here’s an example with a simple matrix:

library(ggalign)

# Sample data
mat <- read.table(
    textConnection(
        "s1,s2,s3
         snv;indel,snv,indel
         ,snv;indel,snv
         snv,,indel;snv"
    ),
    row.names = NULL,
    header = TRUE,
    sep = ",",
    stringsAsFactors = FALSE
)
rownames(mat) <- c("g1", "g2", "g3")
mat <- as.matrix(mat)

# Example 1: Manually order rows using numeric indices
ggoncoplot(
    mat,
    map_width = c(snv = 0.5),
    map_height = c(indel = 0.9),
    reorder_row = FALSE
) +
    scale_fill_brewer(palette = "Dark2", na.translate = FALSE) +
    # Use anno_left() or anno_right() for row ordering; for columns, use anno_top() or anno_bottom()
    anno_left() +
    align_order(c(2, 3, 1))  # Orders rows as g2, g3, g1

Image

# Example 2: Manually order rows using row names
ggoncoplot(
    mat,
    map_width = c(snv = 0.5),
    map_height = c(indel = 0.9),
    reorder_row = FALSE
) +
    scale_fill_brewer(palette = "Dark2", na.translate = FALSE) +
    anno_left() +
    align_order(c("g2", "g1", "g3"))  # Orders rows as g2, g1, g3

Image

For row ordering, you can use either numeric indices (e.g., c(2, 3, 1)) or character names (e.g., c("g2", "g1", "g3")) if your matrix has row names. For column ordering, simply replace anno_left() with anno_top() or anno_bottom() and specify the sample order in align_order(). Note the ordering specified is from bottom to the top or from left to the right which following the ggplot2 coordinates.

Let me know if you have more questions or need help adapting this to your data!

@Yunuuuu Yunuuuu added the documentation Improvements or additions to documentation label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants