schex
schex copied to clipboard
Pass `colData(sce)` to enable facetting (feature request)
Feature request: would be super handy to pass along the cell-level metadata (colData(sce)
) to enable facetting.
Actually hmm. More complicated than I thought because you'd have to also calculate based on the rule how to represent colData...majority would make sense for factors, but not so much for continuous data.
The cell-level meta data can be passed along using the plot_hexbin_meta
function. Is that what you are after?
To be more explicit, let's say we have an sce
with a variable in its colData
of batch
, and I want to plot the cluster
assignment against batch
on the UMAP
plot.
So if I was in ggplot2, I might do the following:
ggplot(data, aes(x = UMAP1, y = UMAP2, colour = cluster) +
facet_wrap(~ batch) +
geom_point()
So I'm wondering if there might be a way to similarly enable downstream facetting. The catch is though, that the plot_hexbin_*()
functions would have to do calculations with respect to the facetting variable (in this example, batch
) as opposed to globally.
Right now the cell-level meta can't be split into facets because the resulting calculation comes from all the data, rather than being "with respect to X".
A workaround for now would be creating separate objects for each instance of the variable of interest, and then running make_hexbin
and plot_hexbin_*
on them. The only downside being that the hexbins are not consistent across the objects.
Actually faceting might be easier to facilitate with simple subsetting, i.e.
library(schex)
library(TENxPBMCData)
library(scater)
library(cowplot)
tenx_pbmc3k <- TENxPBMCData(dataset = "pbmc3k")
rm_ind <- calcAverage(tenx_pbmc3k)<0.1
tenx_pbmc3k <- tenx_pbmc3k[!rm_ind,]
tenx_pbmc3k <- normalize(tenx_pbmc3k)
tenx_pbmc3k <- runPCA(tenx_pbmc3k)
tenx_pbmc3k <- make_hexbin( tenx_pbmc3k, 80, dimension_reduction = "PCA")
tenx_pbmc3k$batch <- as.factor(sample(c(rep("A", 10), "B"), dim(tenx_pbmc3k)[2], replace=TRUE))
# assume we facet with respect to batch
pp <- lapply(levels(tenx_pbmc3k$batch), function(x){
tmp <- tenx_pbmc3k[,tenx_pbmc3k$batch==x]
tmp <- make_hexbin(tmp, 20, dimension_reduction = "PCA")
plot_hexbin_gene(tmp, type="counts", gene="ENSG00000106028", action="prop_0")
})
plot_grid(plotlist=pp)