<p>Below a few lines of code that accompany BC Wang's answer.
After using MergeSeurat the sample name will be added to meta data under orig.ident. this can then be used to color the tSNE either using group.by or pt.shape. The former will show colors for each sample, the latter will color each cluster and give sample id another shape.</p>

<pre><code>path1 &lt;- file.path("path to 10x sample 1")
path2 &lt;- file.path("path to 10x sample 2")

S1 &lt;- Read10X(data.dir = path1)
S2 &lt;- Read10X(data.dir = path2)
S1 &lt;- CreateSeuratObject(raw.data = S1, min.cells = 3, project = "S1")
S2 &lt;- CreateSeuratObject(raw.data = S2, min.cells = 3, project = "S2")

s.combined &lt;- MergeSeurat(object1 = S1, object2 = S2, add.cell.id1 = "S1", 
            add.cell.id2 = "S2", project = "2samples")
</code></pre>

<p>All data analysis goes here:
RunTSNE etc...</p>

<h2>Plot the data</h2>

<pre><code>TSNEPlot(s.combined, group.by ="orig.ident")
TSNEPlot(s.combined, pt.shape="orig.ident")
</code></pre>

CC BY-SA 4.0
2018-10-10T20:03:55.893Z
2018-10-10T20:03:55.893Z
Mack123456
<p>If I understand your question correctly, you are trying to present the tSNE plot coloring and labeling the cells representations based on the original sample ID, i.e. which Seurat object it was from. </p>

<p>I think they offered a vignette on that. Please check this link. <a href="https://satijalab.org/seurat/merge_vignette.html" rel="nofollow noreferrer">https://satijalab.org/seurat/merge_vignette.html</a></p>

<p>Basically, you can add the sample name for the cells in the argument option in <code>MergeSeurat</code> function. Please check the documentation on <code>MergeSeurat</code> function as well. </p>

<p>When I did this, I have a lot of samples to be merged, so I simply saved the sample info for every cell in each sample to different objects. You can also use <code>AddMetadata</code> to do it as well.</p>

<p>Hope that helps. </p>

CC BY-SA 4.0
2018-10-10T10:35:24.250Z
2018-10-10T10:35:24.250Z
BC Wang
<p>It is impossible to create the same tSNE plot without knowing which seed you used. tSNE plots are not like PCAs you don't get the same results when using the same data.</p>

<p>But if you want another tSNE plot with a color differentiating from which object each sample comes you'll need a column with these information and color the plot by it. </p>

CC BY-SA 4.0
2018-10-03T16:08:15.360Z
Seurat allows you to visualize tSNE plots with gene expression data painted on top using the FeaturePlot function. I assume there must be a way to do the same thing with meta data such as original IDs. I just can't find anything online that shows how to do this.
David Tatarakis
CC BY-SA 4.0
2018-10-03T07:09:01.530Z
2018-10-03T07:09:01.530Z
llrs
<p>I am working with single-cell RNA-seq data, using the R package "Seurat" to cluster and visual data-points.</p>

<p>I had two single cell datasets from which I generated two Seurat objects. I then combined the two using MergeSeurat. I did differential gene expression analysis, performed clustering, and ran a tSNE plot.</p>

<p>Now what I want to do is create that same tSNE plot, but color each cell according to the original object from which it came. How do I do this?</p>

CC BY-SA 4.0
2018-10-02T15:56:53.507Z
@MrFlick Don’t you agree that it’s a fairly clear question for domain experts (which, according to your profile, you are)? I’ve flagged it to be moved to bioinformatics.SE.
Konrad Rudolph
<r><rna-seq><visualization><seurat>
Seurat Merged objects tSNE - How to paint on original IDs?
# Seurat Merged objects tSNE - How to paint on original IDs?

(Asked by: username_0 on 2018-10-02)

I am working with single-cell RNA-seq data, using the R package "Seurat" to cluster and visual data-points.

I had two single cell datasets from which I generated two Seurat objects. I then combined the two using MergeSeurat. I did differential gene expression analysis, performed clustering, and ran a tSNE plot.

Now what I want to do is create that same tSNE plot, but color each cell according to the original object from which it came. How do I do this?

**Tags:** r, rna-seq, visualization, seurat
> **Comments:**
> **username_1**: @MrFlick Don’t you agree that it’s a fairly clear question for domain experts (which, according to your profile, you are)? I’ve flagged it to be moved to bioinformatics.SE.  

---

## 3 answers

### Answer by username_2 on 2018-10-10. Score: 3

Below a few lines of code that accompany BC Wang's answer.
After using MergeSeurat the sample name will be added to meta data under orig.ident. this can then be used to color the tSNE either using group.by or pt.shape. The former will show colors for each sample, the latter will color each cluster and give sample id another shape.
path1 <- file.path("path to 10x sample 1")
path2 <- file.path("path to 10x sample 2")

S1 <- Read10X(data.dir = path1)
S2 <- Read10X(data.dir = path2)
S1 <- CreateSeuratObject(raw.data = S1, min.cells = 3, project = "S1")
S2 <- CreateSeuratObject(raw.data = S2, min.cells = 3, project = "S2")

s.combined <- MergeSeurat(object1 = S1, object2 = S2, add.cell.id1 = "S1", 
            add.cell.id2 = "S2", project = "2samples")

All data analysis goes here:
RunTSNE etc...
Plot the data
TSNEPlot(s.combined, group.by ="orig.ident")
TSNEPlot(s.combined, pt.shape="orig.ident")


---

### Answer by username_3 on 2018-10-10. Score: 1

If I understand your question correctly, you are trying to present the tSNE plot coloring and labeling the cells representations based on the original sample ID, i.e. which Seurat object it was from.

I think they offered a vignette on that. Please check this link. <https://satijalab.org/seurat/merge_vignette.html>

Basically, you can add the sample name for the cells in the argument option in `MergeSeurat` function. Please check the documentation on `MergeSeurat` function as well.

When I did this, I have a lot of samples to be merged, so I simply saved the sample info for every cell in each sample to different objects. You can also use `AddMetadata` to do it as well.

Hope that helps.


---

### Answer by username_4 on 2018-10-03. Score: 0

It is impossible to create the same tSNE plot without knowing which seed you used. tSNE plots are not like PCAs you don't get the same results when using the same data.

But if you want another tSNE plot with a color differentiating from which object each sample comes you'll need a column with these information and color the plot by it.

> **Comments:**
> **username_0**: Seurat allows you to visualize tSNE plots with gene expression data painted on top using the FeaturePlot function. I assume there must be a way to do the same thing with meta data such as original IDs. I just can't find anything online that shows how to do this.  

---

