Question: How to assign colors by given values for t-SNE plot
0
gravatar for marshelma
20 months ago by
marshelma0
marshelma0 wrote:

I have a matrix, each data point in this matrix have Binomial variable X1 to Xm, and a continuous variable Y.

I used Rtsne() in R to separate all data points by variable X1 to Xm. After that, instead of clustering them by k-mean or hcluster, what I want is to add color on all dots based on their Y values to see how the dots with different Y value are separated.

Could anyone tell me how to add color for this purpose?

The following code are used to generate the s-SNE plot and draw the plot:

tsne_model_1 = Rtsne(as.matrix(term_tsne), check_duplicates=FALSE, pca=TRUE, perplexity=10, theta=0.5, dims=2)
d_tsne_1 = as.data.frame(tsne_model_1$Y)  
ggplot(d_tsne_1, aes(x=V1, y=V2)) +  
  geom_point(size=0.25) +
  guides(colour=guide_legend(override.aes=list(size=6))) +
  xlab("") + ylab("") +
  ggtitle("t-SNE of 533 terms") +
  theme_light(base_size=20) +
  theme(axis.text.x=element_blank(),
        axis.text.y=element_blank())

term_tsne is the data matrix I used for t-SNE, colnames(term_tsne) return X1, X2....Xm, Y

R • 3.4k views
ADD COMMENTlink modified 20 months ago by Jean-Karim Heriche21k • written 20 months ago by marshelma0

If you were to provide the exact commands you use, it would be easier for people to know where you are in terms of the solution and how best they can steer you in the right direction.

ADD REPLYlink written 20 months ago by RamRS25k

Thank you! I added the code to the question.

ADD REPLYlink written 20 months ago by marshelma0

Please use the code formatting button to make code more legible.

ADD REPLYlink written 20 months ago by Jean-Karim Heriche21k
0
gravatar for Jean-Karim Heriche
20 months ago by
EMBL Heidelberg, Germany
Jean-Karim Heriche21k wrote:

This is a ggplot2 question. Plenty of examples can be found online. Maybe something along the lines of

geom_point(aes(x=X, y=Y, color=...)) + scale_colour_*(...)

Since Y is continuous, you'll need to either map values to a colour gradient or map ranges to discrete colours.

ADD COMMENTlink written 20 months ago by Jean-Karim Heriche21k

Thank you for the suggestion, I will check if I can work it out.

ADD REPLYlink written 20 months ago by marshelma0

Sorry, I have a feature plot in seurat, how I can change the color of some cells based on my desire?

ADD REPLYlink written 18 months ago by Za120

Thank you, actually I don't know how and where store my cells. I just would like to highlight some cells in feature plot or tSNE plot

ADD REPLYlink written 18 months ago by Za120
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 2.3.0
Traffic: 711 users visited in the last hour