alanocallaghan / scater

Clone of the Bioconductor repository for the scater package.
https://bioconductor.org/packages/devel/bioc/html/scater.html
94 stars 40 forks source link

Include colData in plotReducedDim ggplot object p$data? #185

Closed antagomir closed 1 year ago

antagomir commented 1 year ago

I was willing to add some advanced visualization on top of the plotReducedDim (ggplot) output that would utilize both colData of the original data object, and coordinates in reducedDim.

In practice, I will need need to created a new data frame manually, combinding reducedDim coordinates and original colData, then use this as the new input data for additional ggplot layers.

It would be handy if plotReducedDim could include colData from the original object in the output ggplot data (p$data). This would be relatively easy to add, and it could be optional.

If this is something to consider, we could prepare a PR.

If there are better general-purpose solutions for combining reducedDim and colData for new plots than the one I described, I would love to hear.

antagomir commented 1 year ago

Here an example using TreeSummarizedExperiment objects (which inherit SCE):

# Load libraries
library(mia)
library(scater)

# Load demo data
data(hitchip1006, package="miaTime")
tse <- hitchip1006

# Run MDS to get reducedDim
tse <- runMDS(tse, exprs_values="counts")

# Plot reducedDim and retrieve ggplot object
p <- plotReducedDim(tse, dimred="MDS")

# Add trajectory between data points from the same subject
p + geom_path(aes(x=X, y=Y, group=subject),
              data = data.frame(reducedDim(tse), colData(tse))
antagomir commented 1 year ago

I realized that the solution (last point) is so straighforward in practice that this does not necessarily require updates into plotReducedDim functionality.

alanocallaghan commented 1 year ago

What about scuttle::makePerCellDF?

antagomir commented 1 year ago

Ah yes, perfect!

alanocallaghan commented 1 year ago

No bother, I might add a seealso to some of the docs (partly to remind myself)