Skip to content

plotOrdination#191

Open
TuomasBorman wants to merge 7 commits intodevelfrom
plotOrdination
Open

plotOrdination#191
TuomasBorman wants to merge 7 commits intodevelfrom
plotOrdination

Conversation

@TuomasBorman
Copy link
Contributor

We have been using scater::plotReducedDim() to visualize reduced dimensionalities. However, it has couple limitations. For instance, it does not have functionality to add ellipses or to connect paired samples. The idea of plotOrdination() is to create a method that allows us to create easily visualizations commonly used in microbiome context. This can be easily extended later if needed.

I checked the literature, and identified the plots below. Is there other layouts that should be implemented?

data("Tengeler2020")
tse <- Tengeler2020
tse <- transformAssay(tse, method = "clr", pseudocount = TRUE)
tse <- scater::runPCA(tse, assay.type = "clr")
plotOrdination(tse, "PCA", colour.by = "patient_status")

image

plotOrdination(tse, "PCA", colour.by = "patient_status", fill.by = "patient_status", add.ellipse = TRUE)

image

plotOrdination(tse, "PCA", colour.by = "patient_status", add.points = FALSE, add.ellipse = TRUE)

image

plotOrdination(tse, "PCA", add.density = TRUE, colour.by = "patient_status")

image

plotOrdination(tse, "PCA", colour.by = "patient_status", add.centroids = TRUE)

image

plotOrdination(tse, "PCA", colour.by = "patient_status", add.centroids = TRUE, add.rotation = TRUE)

image

plotOrdination(tse, "PCA", colour.by = "patient_status", add.centroids.lines = TRUE)

image

plotOrdination(tse, "PCA", colour.by = "patient_status", add.centroids = TRUE, add.vectors = TRUE)

image

library(microbiomeDataSets)

mae <- microbiomeDataSets::peerj32()
tse <- getWithColData(mae, 1)
tse <- transformAssay(tse, method = "clr", pseudocount = TRUE)
tse <- scater::runPCA(tse, assay.type = "clr")
plotOrdination(tse, "PCA", colour.by = "group", pair.by = "subject")

image

plotOrdination(tse, "PCA", colour.by = "group", pair.by = "subject", sort.by = "time", shape.by = "sex")

image

@TuomasBorman
Copy link
Contributor Author

@antagomir Any further ideas visualizing PCA/PCoA results?

@antagomir
Copy link
Member

antagomir commented May 16, 2025

Seems great.

  1. Explained percentages on the axes are a common need.
  2. This should support, at least implicitly, other transformations besides CLR (e.g. robust CLR..) or other distances than Aitchison (e.g. robust Aitchison..)
  3. Sometimes scaling of features is necessary (zero mean, unit variance) because this makes the loadings more directly comparable. To consider whether it is done before the function or as part of it.
  4. Should be synchronized with plotLoadings()?

@TuomasBorman
Copy link
Contributor Author

TuomasBorman commented May 16, 2025

2.-3. This is working just like scater::plotReducedDim(). This does not do any calculations.

@antagomir
Copy link
Member

2.-3. This is working just like scater::plotReducedDim(). This does not do any calculations.

Oh yes.

@TuomasBorman
Copy link
Contributor Author

Remember to update plotRDA. Make sure that all options that are in plotReducedDim are also available in this new function.

Check also that the naming of arguments is harmonized. Currently, some of the arguments are passed to plotReducedDim without touching them, leading to usage of to naming conventions. For instance, this does not work

plotRDA(tse, dimred = "RDA", colour.by = "disease", shape.by = "gender")

but this works

plotRDA(tse, dimred = "RDA", colour.by = "disease", shape_by = "gender")

@TuomasBorman
Copy link
Contributor Author

Add option for adding sample names:

add.colnames = FALSE

It can take either TRUE, FALSE or vector value that has the displayed sample names.

@TuomasBorman
Copy link
Contributor Author

in plotRDA (and plotOrdination) make sure that axis labels are from reducedDim() results. Currently, plotRDA overwrites somewhere the axis labels. In the example below, y axis should be MDS1 as there is only one constrained axis (dbRDA1). However, they are now dbRDA1 and dbRDA2.

library(miaViz)

data(GlobalPatterns)

tse <- GlobalPatterns
tse <- tse[, tse[["SampleType"]] %in% c("Soil", "Feces")]
tse <- addRDA(tse, assay.type = "counts", formula = x ~ SampleType)
plotRDA(tse, "RDA")
# The y axis should be MDS1. Take names directly from reducedDim
colnames(reducedDim(tse, "RDA"))

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.

2 participants