Hello everyone,
I have looked in the forum but could not find any information. I want to add labels on cluster in a t-SNE plot. I am using Scater and Scran packages for scRNA-Seq data analysis. I also want to change the color palette but could not achieve it too.
I used +geomlabelrepel(data$clusters) but R crashed with that command.
Text labels can be added via geom_text or annotate, provided you know the coordinates you are interested in. For example, the next version of scater::plotReducedDim provides a text_by= argument that adds an identifying label at the centre of each cluster, which is useful in cases where there are more clusters than unique colours.
library(scater)
## Set up an example SingleCellExperiment
data("sc_example_counts")
data("sc_example_cell_info")
example_sce <- SingleCellExperiment(
assays = list(counts = sc_example_counts),
colData = sc_example_cell_info
)
example_sce <- normalize(example_sce)
## Make labels at any coordinate you wish.
gg <- plotPCA(example_sce)
gg + geom_text(aes(label=label), data=data.frame(X=0, Y=0, label="YAY"))
Colours should be changeable by overriding the existing fill.
gg <- plotPCA(example_sce, colour_by="Treatment")
gg # orange and blue
gg + scale_fill_manual(values=c(treat1="red", treat2="green"))
Since the original answer was written, the point type in scater has changed so the colour aesthetic is used now instead of fill. You could instead use scale_colour_manual.
Thank you Aaron for your answer. Basically, I can add labels on cluster with cluster coordinates in plot.
This new argument will be so useful I believe. Thank you again.
I found that I also needed to add an extra aesthetics argument:
Since the original answer was written, the point type in scater has changed so the colour aesthetic is used now instead of fill. You could instead use
scale_colour_manual
.Ah, thanks Alan!