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

plotExpression Group Labels #212

Closed DarioS closed 3 weeks ago

DarioS commented 3 weeks ago

It would be convenient to be able to define a custom labeller so that the cell type may be shown in a group's title with marker gene.

alanocallaghan commented 3 weeks ago

You're going to have to be more specific

DarioS commented 3 weeks ago

O.K. So, instead of just ACTA2, CD34 headings, generate headings like mCAF (ACTA2), iCAF (CD34) by a facet labeller. I looked at data part of object and had a guess + facet_wrap(vars(colour_by), labeller = geneCellTypeLabeller) but it was not right. So, basically hoping to paste known gene marker name to cell type name without editing SingleCellExperiment.

alanocallaghan commented 3 weeks ago

Not wishing to be fussy, but I was rather hoping for a reproducible code example, with current output plus expected output

DarioS commented 3 weeks ago

Ah, I got it to work with as_labeller while designing the minimal reproducible example.

library(scater)
library(ggplot2)
markers <- c("Gene_0001", "Gene_0050", "Gene_0010")
example_sce <- mockSCE()
example_sce <- logNormCounts(example_sce)
example_sce$cellType <- LETTERS[1:4]
aLabeller <- setNames(c("Type A (Gene_0001)", "Type B (Gene_0050)", "Type C (Gene_0010)"),
                      c("Gene_0001", "Gene_0050", "Gene_0010"))

plotExpression(example_sce, markers, x = "cellType", colour_by = "cellType") +
              facet_wrap(vars(Feature), labeller = as_labeller(aLabeller))

image

This compares a marker gene in its known cell type and all others alongside that.