Answers.Body: <p>Seurat puts the label in the tSNE plot according to the <strong>@ident</strong> slot of the Seurat object.</p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>For instance if your Seurat object is called src:</p>
  
  <pre><code>identity=as.factor(sampleInfo$timepoints)
  names(identity)=sampleInfo$cellName
  src@ident=identity
  </code></pre>
  
  <p>And then plot the tSNE. Something like this should work after adapting it to your metadata.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-08T15:02:20.850Z
Answers.Text: Sorry what is sampleInfo?
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-08T15:03:33.407Z
Answers.Text: What you call time in your example. cellName could be your s0.1, etc and timepoints your h0, etc
Answers.UserDisplayName: jxx_fa
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-08T15:07:21.323Z
Answers.Text: Sorry says that  > TSNEPlot(object = al)
  Error in seq.default(h[1], h[2], length.out = n) : 
    'to' must be a finite number
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-08T15:10:51.157Z
Answers.Text: 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?
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-08T15:14:08.510Z
Answers.Text: Yes, it is supposed to contain similar information. I put this name randomly. In your case it would be your time data frame
Answers.UserDisplayName: jxx_fa
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-08T15:18:05.070Z
Answers.Text: Sorry but says that    > TSNEPlot(object = al)
  Error in seq.default(h[1], h[2], length.out = n) : 
    'to' must be a finite number
  >
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-08T13:54:06.830Z
Answers.LastActivityDate: 2018-08-08T13:54:06.830Z
Answers.UserDisplayName: jxx_fa
Body: <p>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. </p>
  
  <p>I first created a file in one column is name of my cells and in second colour the corresponding time point </p>
  
  <p>Like so</p>
  
  <pre><code>    time
  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
  </code></pre>
  
  <p>I read my file</p>
  
  <pre><code>time &lt;- read.table("time.txt",header = TRUE)
  seurat@meta.data$time &lt;- time
  TSNEPlot(object = seurat, group.by = "time")
  </code></pre>
  
  <p>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</p>
  
  <p>says that    </p>
  
  <pre><code>&gt; TSNEPlot(object = al)
  Error in seq.default(h[1], h[2], length.out = n) : 
    'to' must be a finite number 
  </code></pre>
  
  <p>when I changed <code>names(identity)=sampleInfo$cellName</code> to <code>names(identity)=src$cellName</code></p>
  
  <p>that worked but again the position of cells changed that I don't want that :(</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-08T13:47:38.883Z
Comments.Text: 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.
Comments.UserDisplayName: Matt Bashton
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-08T13:48:15.460Z
Comments.Text: 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.
Comments.UserDisplayName: Matt Bashton
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-08T13:56:32.790Z
Comments.Text: Please  no negative point :( If I lose my reputation I can not ask question anymore
Comments.UserDisplayName: Zizogolu
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-09T08:48:25.870Z
Comments.Text: 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
Comments.UserDisplayName: Zizogolu
Tags: <r><scrnaseq><seurat>
Title: Changing the colour of each cell in tSNE plot
ThreadText: # Changing the colour of each cell in tSNE plot
  
  (Asked by: username_0 on 2018-08-08)
  
  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
  
  ```
      time
  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 :(
  
  **Tags:** r, scrnaseq, seurat
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_1**: 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.  
  > **username_0**: Please  no negative point :( If I lose my reputation I can not ask question anymore  
  > **username_0**: 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  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-08-08. Score: 2 | Accepted answer
  
  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:
  
  ```
  identity=as.factor(sampleInfo$timepoints)
  names(identity)=sampleInfo$cellName
  src@ident=identity
  
  ```
  
  And then plot the tSNE. Something like this should work after adapting it to your metadata.
  
  > **Comments:**
  > **username_0**: Sorry what is sampleInfo?  
  > **username_2**: What you call time in your example. cellName could be your s0.1, etc and timepoints your h0, etc  
  > **username_0**: Sorry says that  > TSNEPlot(object = al) Error in seq.default(h[1], h[2], length.out = n) :    'to' must be a finite number  
  > **username_0**: 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?  
  > **username_2**: Yes, it is supposed to contain similar information. I put this name randomly. In your case it would be your time data frame  
  > **username_0**: Sorry but says that    > TSNEPlot(object = al) Error in seq.default(h[1], h[2], length.out = n) :    'to' must be a finite number >  
  
  ---
  
  