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

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.

Thank you in advance.

scran scater Rtsne ggplot2 scRNA-Seq • 4.5k views
ADD COMMENT
1
Entering edit mode
Aaron Lun ★ 28k
@alun
Last seen 17 hours 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"))
ADD COMMENT
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.

ADD REPLY
0
Entering edit mode

I found that I also needed to add an extra aesthetics argument:

gg + scale_fill_manual(values=c(treat1="red", treat2="green"), aesthetics="colour")
ADD REPLY
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

Ah, thanks Alan!

ADD REPLY

Login before adding your answer.

Traffic: 619 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6