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

Improve plotAbundance #156

Merged
merged 38 commits into from
Nov 1, 2024
Merged

Improve plotAbundance #156

merged 38 commits into from
Nov 1, 2024

Conversation

TuomasBorman
Copy link
Contributor

This PR implements the suggestions made in here: #132

The whole function is now restructured and improved. Even though the function was working, it was too complex to maintain I think. It was not easy to add the suggested things without refactoring the code. That is why the function is now mostly coded again, I think it is much simpler. Moreover, it has many additional capabilities that were not before which makes the function now rather flexible.

Main changes

  1. The code is now simpler. However, all old functionalities are still fully supported.
  2. User can choose manually the order of columns and rows.
  3. Facets are supported now also for columns
  4. Support for paired samples.

Because this has many new features and the Bioconductor release is coming soon, I think it is the wisest to keep this PR open and merge this to the next Bioconductor development version. I can also test this in one of my projects before merging.

Here are few examples on the usage


library(miaViz)
library(patchwork)
data(enterotype, package="mia")
tse <- enterotype
# Apply relative transformation
tse <- agglomerateByPrevalence(tse, prevalence = 0.98)
tse <- transformAssay(tse, method = "relabundance")
tse <- tse[ , complete.cases(colData(tse))]
# Plot with annotation bar
p <- plotAbundance(tse, col.var = "Gender", assay.type = "relabundance")
wrap_plots(p, ncol = 1, heights = c(0.95, 0.05))

image

# Plot with annotation bar and order
p <- plotAbundance(tse, col.var = "Gender", order.col.by = "Gender", assay.type = "relabundance")
wrap_plots(p, ncol = 1, heights = c(0.95, 0.05))

image

# Plot with facets for sample metadata variable
p <- plotAbundance(tse, col.var = "Gender", facet.cols = TRUE, scales = "free_x", assay.type = "relabundance")
p

image

# Plot with facets for multiple sample metadata variables (this requires an additional package that is not dependency)
p <- plotAbundance(tse, col.var = c("Nationality", "Gender"), facet.cols = TRUE, scales = "free_x", assay.type = "relabundance")
p

image

# Add own taxa order
order <- rownames(tse)
order <- c(order[!order%in%c("Bacteroides")], "Bacteroides")
p <- plotAbundance(tse, row.levels = order, assay.type = "relabundance")
p

image

# Prepare data
data("Tengeler2020")
tse <- Tengeler2020
tse <- agglomerateByPrevalence(tse, prevalence = 0.70)
tse <- tse[, 1:12]
colData(tse)[["patient"]] <- rep(paste0("patient", seq_len(4)), ncol(tse) / 4)
colData(tse)[["time_point"]] <- rep(paste0("time", seq_len(20)), each = 4)[1:12]

# Drop patient 1 from 1st time point, patient 2 from 2nd time point and patient 3 and 4 from time point 3
tse <- tse[ , c(2:5, 7:10)]
# Create a plot with paired data for comparison
p <- plotAbundance(
    tse, col.var = "time_point", order.col.by = "patient", as.relative = TRUE,
    paired = TRUE, facet.cols = TRUE, ncol = 1, scales = "free_x")
p

image

@antagomir
Copy link
Member

very nice!

@TuomasBorman TuomasBorman linked an issue Oct 9, 2024 that may be closed by this pull request
Signed-off-by: Daena Rys <rysdaena8@gmail.com>
R/plotAbundance.R Outdated Show resolved Hide resolved
Daenarys8 and others added 7 commits October 14, 2024 11:21
Signed-off-by: Daena Rys <rysdaena8@gmail.com>
Signed-off-by: Daena Rys <rysdaena8@gmail.com>
R/plotAbundance.R Outdated Show resolved Hide resolved
@TuomasBorman TuomasBorman merged commit 94696fa into devel Nov 1, 2024
3 checks passed
@TuomasBorman TuomasBorman deleted the plotabundance_mods branch November 1, 2024 09:08
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

Successfully merging this pull request may close these issues.

plotAbundance improvements
3 participants