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

Change order of samples in metData object #13

Open
beantkapoor786 opened this issue Sep 16, 2024 · 1 comment
Open

Change order of samples in metData object #13

beantkapoor786 opened this issue Sep 16, 2024 · 1 comment

Comments

@beantkapoor786
Copy link

Hello, thank you for building this useful R package. I have made various plots using alignment files and vcf metrics using the PHGmetrics constructor object metData. I was wondering if there is any way to change the order of the samples in this object and subsequently in the generated plots? Thank you.

@beantkapoor786 beantkapoor786 changed the title Change order of samples in PHG graph Change order of samples in metData object Sep 16, 2024
@btmonier
Copy link
Member

btmonier commented Oct 3, 2024

Sorry for the late reply. We currently do not have a simple parameter to pass to the base plot functions, but since these plot objects are modified ggplot objects, we can directly manipulate the data slots for each sub-plot. Here is a reprex for manipulating gVCF plots:

# Get test data and plot
metBase <- system.file(
    "extdata", "toy_gvcf_metrics.tsv", 
    package = "rPHG2"
) |>
    PHGMetrics()

pBase <- metBase |> plotGvcf()

# New sample order
newOrder <- c("Xb02", "Xb03", "Xb01") # old levels (Xb01, Xb02, Xb03)

# Make in-memory copy
pNewOrder <- pBase

# Re-order copy
for(i in seq_len(length(pNewOrder))) {
    pNewOrder[[i]]$data$taxa <- factor(
        pNewOrder[[i]]$data$taxa, 
        levels = newOrder
    )
}

# Inspect
pNewOrder

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