Adding labels on clusters in a t-SNE plot and changing colors
1
0
Entering edit mode
@hamza_karakurt-17704
Last seen 6 months ago

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.

scran scater Rtsne ggplot2 scRNA-Seq • 1.4k views
1
Entering edit mode
Aaron Lun ★ 27k
@alun
Last seen 57 minutes ago
The city by the bay

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"))

0
Entering edit mode

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.