text: user4595: I have a Seurat object
  I want to have both cluster numbers and coloured cells by sample names like this figure (from a Nature paper)
  
  I have tried group.by argument in Seurat but only samples come not cluster numbers like below
  > DimPlot(pbmc, reduction = "umap",group.by = "samples")
  >
  
  [![enter image description here][2]][2]
  Any help that to get something like the first figure? Having cluster numbers and coloured by sample names please
  
  user3541: Here is a solution that makes use of LabelClusters() from Seurat:
  # creating a plot and assigning it to the "plot" variable
  # coloring by sample id and turning labels off
  plot <- 
  DimPlot(
    pbmc,
    reduction = "umap",
    group.by = "some_random_sample_id",
    label = FALSE,
  )
  
  # here is the trick, adding cluster labels to the "data" variable of the "plot"
  # without this, the "plot" object would not have the clustering information but only embeddings and sample id
  plot$data$seurat_clusters<- pbmc@meta.data$seurat_clusters
  
  # and here is a sanity check to see if cluster labels are transferred to the "right places"
  all(rownames(plot$data) == rownames(pbmc@meta.data))
  
  LabelClusters(plot, id = "seurat_clusters")
  
  
  
original_text: 4595: <p>I have a Seurat object</p>
  <p>I want to have both cluster numbers and coloured cells by sample names like this figure (from a Nature paper)</p>
  <p><a href="https://i.stack.imgur.com/ENABR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ENABR.png" alt="enter image description here" /></a></p>
  <p>I have tried <code>group.by</code> argument in Seurat but only samples come not cluster numbers like below</p>
  <pre><code>&gt; DimPlot(pbmc, reduction = &quot;umap&quot;,group.by = &quot;samples&quot;)
  &gt;
  </code></pre>
  <p>[![enter image description here][2]][2]</p>
  <p>Any help that to get something like the first figure? Having cluster numbers and coloured by sample names please</p>
   3541: <p>Here is a solution that makes use of <code>LabelClusters()</code> from <code>Seurat</code>:</p>
  <pre><code># creating a plot and assigning it to the &quot;plot&quot; variable
  # coloring by sample id and turning labels off
  plot &lt;- 
  DimPlot(
    pbmc,
    reduction = &quot;umap&quot;,
    group.by = &quot;some_random_sample_id&quot;,
    label = FALSE,
  )
  
  # here is the trick, adding cluster labels to the &quot;data&quot; variable of the &quot;plot&quot;
  # without this, the &quot;plot&quot; object would not have the clustering information but only embeddings and sample id
  plot<span class="math-container">$data$</span>seurat_clusters&lt;- pbmc@meta.data$seurat_clusters
  
  # and here is a sanity check to see if cluster labels are transferred to the &quot;right places&quot;
  all(rownames(plot$data) == rownames(pbmc@meta.data))
  
  LabelClusters(plot, id = &quot;seurat_clusters&quot;)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/A65yx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A65yx.png" alt="enter image description here" /></a></p>
  