Question: Adding labels on clusters in a t-SNE plot and changing colors
0
gravatar for hamza_karakurt
7 months ago by
hamza_karakurt30 wrote:

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.

ADD COMMENTlink modified 7 months ago by Aaron Lun25k • written 7 months ago by hamza_karakurt30
Answer: Adding labels on clusters in a t-SNE plot and changing colors
1
gravatar for Aaron Lun
7 months ago by
Aaron Lun25k
Cambridge, United Kingdom
Aaron Lun25k wrote:

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 COMMENTlink written 7 months ago by Aaron Lun25k

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 REPLYlink written 7 months ago by hamza_karakurt30
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 312 users visited in the last hour