How to assign colors by given values for t-SNE plot
1
0
Entering edit mode
6.1 years ago
marshelma • 0

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 • 7.8k views
ADD COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

Thank you! I added the code to the question.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
6.1 years ago

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 COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 3239 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