Include colData in plotReducedDim ggplot object p$data?
Closed this issue · 5 comments
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.
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))
I realized that the solution (last point) is so straighforward in practice that this does not necessarily require updates into plotReducedDim functionality.
What about scuttle::makePerCellDF
?
Ah yes, perfect!
No bother, I might add a seealso
to some of the docs (partly to remind myself)