Skip to content

plotOrdination#191

Open
TuomasBorman wants to merge 8 commits into
develfrom
plotOrdination
Open

plotOrdination#191
TuomasBorman wants to merge 8 commits into
develfrom
plotOrdination

Conversation

@TuomasBorman

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@antagomir Any further ideas visualizing PCA/PCoA results?

@antagomir

antagomir commented May 16, 2025

Copy link
Copy Markdown
Member

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

TuomasBorman commented May 16, 2025

Copy link
Copy Markdown
Contributor Author

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

@antagomir

Copy link
Copy Markdown
Member

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

Oh yes.

@TuomasBorman

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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"))

@TuomasBorman

TuomasBorman commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

Add support for joint-RPCA: microbiome/mia#808

Check also plotLoadings and joint-RPCA

@artur-sannikov

artur-sannikov commented May 13, 2026

Copy link
Copy Markdown

We can add ellipses this way:

colnames(p$data)

# r$> colnames(p$data)
# [1] "X"         "Y"         "colour_by" "order_by" 

p <- plotReducedDim(tse, "MDS_Bray", color_by = "group") +
  stat_ellipse(aes(color = colour_by))

The ellipses functionality can be implemented like in the plotOrdination function, but it's not strictly necessary.

@TuomasBorman

Copy link
Copy Markdown
Contributor Author

Thanks! This is very true, but requires knowledge on ggplot class, thus it is little bit "hacky" way

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.

3 participants