I have plotted a tSNE plot of my 1643 cells from 9 time points by seurat like below as 9 clusters. But, you know I should not expected each cluster of cells contains only cells from one distinct time point. For instance, cluster 2 includes cells from time point 16, 14 and even few cells from time point 12. My question is, how I can change the colour of cells here so cells from each time point has a distinct colour does not matter some cells are being clustered somewhere else because this is unavoidable. I have named my cells already so I know cells from each time point but I want to colour cells to nine colours based on the time point they have been sequenced not the cluster they are being grouped by seurat.

I first created a file in one column is name of my cells and in second colour the corresponding time point

Like so

s0.1    h0
s0.2    h0
s0.3    h0
s0.4    h0
s0.5    h0
s0.6    h0
s0.7    h0
s0.8    h0
s0.9    h0
s0.10   h0
s0.11   h0
s0.12   h0
s0.13   h0
s0.14   h0
s0.15   h0
s0.16   h0
s0.17   h0
s0.18   h0
s0.19   h0
s0.20   h0
s0.21   h0
s0.22   h0
s0.23   h0
s0.24   h0
s0.25   h0

I read my file

time <- read.table("time.txt",header = TRUE)
seurat@meta.data$time <- time
TSNEPlot(object = seurat, group.by = "time")

Sorry in my code colour of tSNE changed also the position of cells changed that I don't want that. I want to change the color of cells but they are still in the same cluster

says that

> TSNEPlot(object = al)
Error in seq.default(h[1], h[2], length.out = n) : 
  'to' must be a finite number 

when I changed names(identity)=sampleInfo$cellName to names(identity)=src$cellName

that worked but again the position of cells changed that I don't want that :(

  • 1
    $\begingroup$ If you can extract the underlying data (as this is essentially an xy scatter plot) you can then share it here. Your question then essentially becomes a base R / ggplot2 problem which should enable others to help you better than the screen shot alone. $\endgroup$ Aug 8 '18 at 13:47
  • 1
    $\begingroup$ From an experimental interpretation point of view if your cells are failing to cluster by time point then clearly there is something else going on with your data, again more information would be useful, additionally if you want help with plotting we'd need to know which time point each data point is from. Thus some exemplar data is required for us to be able to help. $\endgroup$ Aug 8 '18 at 13:48
  • 1
    $\begingroup$ Please no negative point :( If I lose my reputation I can not ask question anymore $\endgroup$
    – Exhausted
    Aug 8 '18 at 13:56
  • $\begingroup$ I found the solution if this is my time table data cc <- AddMetaData(object = n, metadata = time) cc <- SetAllIdent(object = cc, id = "time") TSNEPlot(object = cc) This only colours the cells based on the time point they are $\endgroup$
    – Exhausted
    Aug 9 '18 at 8:48

Seurat puts the label in the tSNE plot according to the @ident slot of the Seurat object.

By default, if you do the tSNE without computing the clusters and you have the correct metadata in the object, the labels should be pointing to your timepoints not to the clusters.

If it is not the case, what you have to do its to change this slot to reflect to which timepoint belong each cell you are plotting.

For instance if your Seurat object is called src:


And then plot the tSNE. Something like this should work after adapting it to your metadata.

  • $\begingroup$ Sorry what is sampleInfo? $\endgroup$
    – Exhausted
    Aug 8 '18 at 15:02
  • $\begingroup$ What you call time in your example. cellName could be your s0.1, etc and timepoints your h0, etc $\endgroup$
    – plat
    Aug 8 '18 at 15:03
  • $\begingroup$ Sorry says that > TSNEPlot(object = al) Error in seq.default(h[1], h[2], length.out = n) : 'to' must be a finite number $\endgroup$
    – Exhausted
    Aug 8 '18 at 15:07
  • $\begingroup$ Sorry I can nit understand. I have the name of my cells and time points as I showed in my question, so sampleInfo is name of my time contains cell names and time points? $\endgroup$
    – Exhausted
    Aug 8 '18 at 15:10
  • $\begingroup$ Yes, it is supposed to contain similar information. I put this name randomly. In your case it would be your time data frame $\endgroup$
    – plat
    Aug 8 '18 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.