<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Plotting #1: Analysis Plots • scCustomize</title>
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/flatly/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="Plotting #1: Analysis Plots">
<meta property="og:description" content="scCustomize">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target="#toc">
    

    <div class="container template-article">
      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">scCustomize</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="">2.1.2</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../index.html">Getting Started</a>
</li>
<li>
  <a href="../articles/Installation.html">Install</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
    Vignettes
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Plotting Vignettes</li>
    <li>
      <a href="../articles/Gene_Expression_Plotting.html">Plotting #1: General Analysis Plots</a>
    </li>
    <li>
      <a href="../articles/QC_Plots.html">Plotting #2: QC Plots</a>
    </li>
    <li>
      <a href="../articles/Sequencing_QC_Plots.html">Plotting #3: Sequencing QC Plots/Analysis</a>
    </li>
    <li>
      <a href="../articles/Iterative_Plotting.html">Plotting #4: Iterative Plotting Functions</a>
    </li>
    <li>
      <a href="../articles/Color_Palettes.html">Customized Color Palettes &amp; Themes</a>
    </li>
    <li class="divider">
    </li>
<li class="dropdown-header">Helpers &amp; Utilities</li>
    <li>
      <a href="../articles/Helpers_and_Utilities.html">General Helpers &amp; Utilities</a>
    </li>
    <li>
      <a href="../articles/Read_and_Write_Functions.html">Read &amp; Write Data Functions</a>
    </li>
    <li>
      <a href="../articles/Object_Conversion.html">Object/Assay Format Conversion</a>
    </li>
    <li>
      <a href="../articles/Markers_and_Cluster_Annotation.html">Marker Identification &amp; Cluster Annotation Helpers</a>
    </li>
    <li>
      <a href="../articles/Statistics.html">Statistics Functions</a>
    </li>
    <li>
      <a href="../articles/Update_Gene_Symbols.html">Updating Gene Symbols</a>
    </li>
    <li>
      <a href="../articles/Misc_Functions.html">Misc Functions</a>
    </li>
    <li class="divider">
    </li>
<li class="dropdown-header">Other Package Interactivity/Functions</li>
    <li>
      <a href="../articles/LIGER_Functions.html">LIGER Plotting &amp; Functionality</a>
    </li>
    <li>
      <a href="../articles/Cell_Bender_Functions.html">Cell Bender Functionality &amp; Plotting</a>
    </li>
  </ul>
</li>
<li>
  <a href="../news/index.html">News/Changelog</a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li>
  <a href="../articles/FAQ.html">FAQ</a>
</li>
      </ul>
<ul class="nav navbar-nav navbar-right">
<li>
  <a href="https://github.com/samuel-marsh/scCustomize/" class="external-link">
    <span class="fab fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      

      </header><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
      <h1 data-toc-skip>Plotting #1: Analysis Plots</h1>
            
            <h4 data-toc-skip class="date">Compiled: February 28,
2024</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/samuel-marsh/scCustomize/blob/HEAD/vignettes/articles/Gene_Expression_Plotting.Rmd" class="external-link"><code>vignettes/articles/Gene_Expression_Plotting.Rmd</code></a></small>
      <div class="hidden name"><code>Gene_Expression_Plotting.Rmd</code></div>

    </div>

    
    
<hr>
<style>
p.caption {
  font-size: 0.9em;
}
</style>
<div class="section level2">
<h2 id="customizing-plots-for-enhancedsimplified-visualization">Customizing Plots for Enhanced/Simplified Visualization<a class="anchor" aria-label="anchor" href="#customizing-plots-for-enhancedsimplified-visualization"></a>
</h2>
<p>While the default plots from Seurat and other packages are often very
good they are often modified from their original outputs after plotting.
scCustomize seeks to simplify this process and enhance some of the
default visualizations.</p>
<p>Even simple things like adding the same two ggplot2 themeing options
to every plot can be simplified for end user (and enhance
reproducibility and code errors) by wrapping them inside a new
function.</p>
<p>For this tutorial, I will be utilizing microglia data from Marsh et
al., 2022 (<a href="https://doi.org/10.1038/s41593-022-01022-8" class="external-link"><em>Nature
Neuroscience</em></a>) the mouse microglia (Figure 1) referred to as
<code>marsh_mouse_micro</code> and the human post-mortem snRNA-seq
(Figure 3) referred to as <code>marsh_human_pm</code> in addition to the
pbmc3k dataset from SeuratData package.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org" class="external-link">ggplot2</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org" class="external-link">dplyr</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://magrittr.tidyverse.org" class="external-link">magrittr</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://patchwork.data-imaginist.com" class="external-link">patchwork</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://sjmgarnier.github.io/viridis/" class="external-link">viridis</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://satijalab.org/seurat" class="external-link">Seurat</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/samuel-marsh/scCustomize" class="external-link">scCustomize</a></span><span class="op">)</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/traversc/qs" class="external-link">qs</a></span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Load Marsh et al., 2022 datasets</span></span>
<span><span class="va">marsh_mouse_micro</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/qs/man/qread.html" class="external-link">qread</a></span><span class="op">(</span>file <span class="op">=</span> <span class="st">"assets/marsh_2020_micro.qs"</span><span class="op">)</span></span>
<span><span class="va">marsh_human_pm</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/qs/man/qread.html" class="external-link">qread</a></span><span class="op">(</span>file <span class="op">=</span> <span class="st">"assets/marsh_human_pm.qs"</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Load pbmc dataset</span></span>
<span><span class="va">pbmc</span> <span class="op">&lt;-</span> <span class="fu">pbmc3k.SeuratData</span><span class="fu">::</span><span class="va"><a href="https://rdrr.io/pkg/pbmc3k.SeuratData/man/pbmc3k.final.html" class="external-link">pbmc3k.final</a></span></span></code></pre></div>
<p>We’ll add some random meta data variables to pbmc data form use in
this vignette</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">pbmc</span><span class="op">$</span><span class="va">sample_id</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/sample.html" class="external-link">sample</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"sample1"</span>, <span class="st">"sample2"</span>, <span class="st">"sample3"</span>, <span class="st">"sample4"</span>, <span class="st">"sample5"</span>, <span class="st">"sample6"</span><span class="op">)</span>, size <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/nrow.html" class="external-link">ncol</a></span><span class="op">(</span><span class="va">pbmc</span><span class="op">)</span>,</span>
<span>    replace <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="va">pbmc</span><span class="op">$</span><span class="va">treatment</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/sample.html" class="external-link">sample</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Treatment1"</span>, <span class="st">"Treatment2"</span>, <span class="st">"Treatment3"</span>, <span class="st">"Treatment4"</span><span class="op">)</span>, size <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/nrow.html" class="external-link">ncol</a></span><span class="op">(</span><span class="va">pbmc</span><span class="op">)</span>,</span>
<span>    replace <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<div class="section level3">
<h3 id="general-notes">General Notes<a class="anchor" aria-label="anchor" href="#general-notes"></a>
</h3>
<ul>
<li>Parameter names
<ul>
<li>Customized plots that take their origin from Seurat share many
direct parameter names from their Seurat equivalents (i.e.,
<code>split.by</code>) but some others use the scCustomize convention so
as to be universal throughout the package (i.e.,
Seurat=cols:scCustomize=colors_use).</li>
<li>Many of the most used parameters for Seurat-based functions have
implemented as direct parameter in scCustomize versions allowing for
easy tab-completion when calling functions.</li>
<li>However, for simplicity of function calls this is not comprehensive.
However, most scCustomize plotting functions contain <code>...</code>
parameter to allow user to supply any of the parameters for the original
Seurat (or other package) function that is being used under the
hood.<br>
</li>
</ul>
</li>
<li>ggplot2/patchwork Modifications
<ul>
<li>All scCustomize plotting functions return either ggplot2 or
patchwork objects allowing for easy additional plot/theme modifications
using ggplot2/patchwork grammar.<br>
</li>
</ul>
</li>
<li>Seurat Function Parameters
<ul>
<li>Most scCustomize plotting functions contain <code>...</code>
parameter to allow user to supply any of the parameters for the original
Seurat function that is being used under the hood.</li>
</ul>
</li>
</ul>
</div>
<div class="section level3">
<h3 id="plotting-highly-variable-genes-pc-loadings">Plotting Highly Variable Genes &amp; PC Loadings<a class="anchor" aria-label="anchor" href="#plotting-highly-variable-genes-pc-loadings"></a>
</h3>
<div class="section level4">
<h4 id="plotting-highly-variable-genes">Plotting highly variable genes<a class="anchor" aria-label="anchor" href="#plotting-highly-variable-genes"></a>
</h4>
<p>scCustomize allows for plotting of highly variable genes with desired
number of points labeled in single function.
<code><a href="../reference/VariableFeaturePlot_scCustom.html">VariableFeaturePlot_scCustom()</a></code> also contains several
additional parameters for customizing visualization.</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Default scCustomize plot</span></span>
<span><span class="fu"><a href="../reference/VariableFeaturePlot_scCustom.html">VariableFeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, num_features <span class="op">=</span> <span class="fl">20</span><span class="op">)</span></span>
<span><span class="co"># Can remove labels if not desired</span></span>
<span><span class="fu"><a href="../reference/VariableFeaturePlot_scCustom.html">VariableFeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, num_features <span class="op">=</span> <span class="fl">20</span>, label <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span><span class="co"># Repel labels</span></span>
<span><span class="fu"><a href="../reference/VariableFeaturePlot_scCustom.html">VariableFeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, num_features <span class="op">=</span> <span class="fl">20</span>, repel <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="co"># Change the scale of y-axis from linear to log10</span></span>
<span><span class="fu"><a href="../reference/VariableFeaturePlot_scCustom.html">VariableFeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, num_features <span class="op">=</span> <span class="fl">20</span>, repel <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>    y_axis_log <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-5-1.png" alt="***A.** Default for `VariableFeaturePlot_scCustom` labels features by default.  Plot can be modified by changing function parameters: **B.** Setting `label = FALSE`, **C.** Setting `repel=TRUE` for feature names, **D.** Setting `y_axis_log=TRUE` to plot y-axis in log scale.*" width="1248"><p class="caption">
<em><strong>A.</strong> Default for
<code>VariableFeaturePlot_scCustom</code> labels features by default.
Plot can be modified by changing function parameters:
<strong>B.</strong> Setting <code>label = FALSE</code>,
<strong>C.</strong> Setting <code>repel=TRUE</code> for feature names,
<strong>D.</strong> Setting <code>y_axis_log=TRUE</code> to plot y-axis
in log scale.</em>
</p>
</div>
<div class="section level5">
<h5 id="label-custom-features">Label custom features<a class="anchor" aria-label="anchor" href="#label-custom-features"></a>
</h5>
<p>In addition to labeling the top variable genes
<code>VariableFeaturePlot_scCustom</code> also supports labeling a
custom set of genes using the <code>custom_features</code>
parameter.</p>
</div>
</div>
<div class="section level4">
<h4 id="plotting-pc-heatmaps-and-loadings-">Plotting PC heatmaps and loadings.<a class="anchor" aria-label="anchor" href="#plotting-pc-heatmaps-and-loadings-"></a>
</h4>
<p>For ease in evaluating PCA results scCustomize provides function
<code><a href="../reference/PC_Plotting.html">PC_Plotting()</a></code> which returns both PC heatmap and Feature
Loading plot in single patchwork layout.</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/PC_Plotting.html">PC_Plotting</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, dim_number <span class="op">=</span> <span class="fl">2</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-6-1.png" width="864" style="display: block; margin: auto;"></p>
<div class="section level5">
<h5 id="iterate-pc-plotting">Iterate PC Plotting<a class="anchor" aria-label="anchor" href="#iterate-pc-plotting"></a>
</h5>
<p>This function can be easily enhanced using iterative version
<code><a href="../reference/Iterate_PC_Loading_Plots.html">Iterate_PC_Loading_Plots()</a></code> to return a PDF document that
contains plots for all desired PCs within object. See function manual
and <a href="https://samuel-marsh.github.io/scCustomize/articles/Iterative_Plotting.html">Iterative
Plotting Vignette</a> for more info.</p>
</div>
</div>
</div>
<div class="section level3">
<h3 id="plot-gene-expression-in-2d-space-pcatsneumap">Plot Gene Expression in 2D Space (PCA/tSNE/UMAP)<a class="anchor" aria-label="anchor" href="#plot-gene-expression-in-2d-space-pcatsneumap"></a>
</h3>
<p>scCustomize has few functions that improve on the default plotting
options/parameters from Seurat and other packages.</p>
<div class="section level4">
<h4 id="featureplots">FeaturePlots<a class="anchor" aria-label="anchor" href="#featureplots"></a>
</h4>
<p>The default plots from<code><a href="https://satijalab.org/seurat/reference/FeaturePlot.html" class="external-link">Seurat::FeaturePlot()</a></code> are very
good but I find can be enhanced in few ways that scCustomize sets by
default.<br>
Issues with default Seurat settings:</p>
<ul>
<li>Parameter <code>order = FALSE</code> is the default, resulting in
potential for non-expressing cells to be plotted on top of expressing
cells.</li>
<li>Using custom color palette with greater than 2 colors bins the
expression by the total number of colors.<br>
</li>
<li>Non-expressing cells are part of same color scale which can make it
difficult to distinguish low expressing cells from non-expressing
cells.</li>
</ul>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Set color palette</span></span>
<span><span class="va">pal</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://sjmgarnier.github.io/viridisLite/reference/viridis.html" class="external-link">viridis</a></span><span class="op">(</span>n <span class="op">=</span> <span class="fl">10</span>, option <span class="op">=</span> <span class="st">"C"</span>, direction <span class="op">=</span> <span class="op">-</span><span class="fl">1</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Create Plots</span></span>
<span><span class="fu"><a href="https://satijalab.org/seurat/reference/FeaturePlot.html" class="external-link">FeaturePlot</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Jun"</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://satijalab.org/seurat/reference/FeaturePlot.html" class="external-link">FeaturePlot</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Jun"</span>, order <span class="op">=</span> <span class="cn">T</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://satijalab.org/seurat/reference/FeaturePlot.html" class="external-link">FeaturePlot</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Jun"</span>, cols <span class="op">=</span> <span class="va">pal</span>, order <span class="op">=</span> <span class="cn">T</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-8-1.png" alt="*`FeaturePlot()` non-ideal results: **A.** default `order = FALSE` compared to **B.** `order = TRUE`, **C.** expression binning when attempting to set custom gradient using `cols` parameter.*" width="1248"><p class="caption">
<em><code><a href="https://satijalab.org/seurat/reference/FeaturePlot.html" class="external-link">FeaturePlot()</a></code> non-ideal results: <strong>A.</strong>
default <code>order = FALSE</code> compared to <strong>B.</strong>
<code>order = TRUE</code>, <strong>C.</strong> expression binning when
attempting to set custom gradient using <code>cols</code>
parameter.</em>
</p>
</div>
<div class="section level5">
<h5 id="featureplot_sccustom-solves-these-issues">
<strong><code>FeaturePlot_scCustom</code> solves these
issues</strong><a class="anchor" aria-label="anchor" href="#featureplot_sccustom-solves-these-issues"></a>
</h5>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Set color palette</span></span>
<span><span class="va">pal</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://sjmgarnier.github.io/viridisLite/reference/viridis.html" class="external-link">viridis</a></span><span class="op">(</span>n <span class="op">=</span> <span class="fl">10</span>, option <span class="op">=</span> <span class="st">"D"</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Create Plots</span></span>
<span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Jun"</span>, order <span class="op">=</span> <span class="cn">F</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Jun"</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Jun"</span>, colors_use <span class="op">=</span> <span class="va">pal</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-10-1.png" alt="*`FeaturePlot_scCustom()` solves issues: **A.** Order can be set to FALSE with optional parameter when desired. **B.** However by default is set to TRUE so additional parameter call not required, **C.** `FeaturePlot_scCustom()` prevents expression binning when supplying custom color palette.*" width="1248"><p class="caption">
<em><code><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom()</a></code> solves issues:
<strong>A.</strong> Order can be set to FALSE with optional parameter
when desired. <strong>B.</strong> However by default is set to TRUE so
additional parameter call not required, <strong>C.</strong>
<code><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom()</a></code> prevents expression binning when
supplying custom color palette.</em>
</p>
</div>
<p>Sometimes <code>order=TRUE</code> can be distracting though and so
can always set it to <code>FALSE</code> <em>In some cases (especially
likely in snRNA-seq), some of the low expression may simply represent
ambient RNA and therefore plotting with <code>order=FALSE</code> may be
advantageous for visualization (or using different plotting
method).</em></p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_human_pm</span>, features <span class="op">=</span> <span class="st">"P2RY12"</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_human_pm</span>, features <span class="op">=</span> <span class="st">"P2RY12"</span>, order <span class="op">=</span> <span class="cn">F</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-12-1.png" width="1248" style="display: block; margin: auto;"></p>
</div>
<div class="section level5">
<h5 id="plotting-non-expressing-cells-as-background-">Plotting non-expressing cells as background.<a class="anchor" aria-label="anchor" href="#plotting-non-expressing-cells-as-background-"></a>
</h5>
<p>As you can see above <code><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom()</a></code> has the
ability to plot non-expressing cells in outside of color scale used for
expressing cells. However it is critical that users pay attention to the
<strong><em>correctly setting the <code>na_cutoff</code>
parameter</em></strong> in <code>FeaturePlot_scCustom</code>.<br>
scCustomize contains a parameter called <code>na_cutoff</code> which
tells the function which values to plot as background. By default this
is set to value that means background is treated as 0 or below.
Depending on what feature, assay, or value you are interested in this
parameter should be modified appropriately.</p>
<p>For instance if plotting module score which contains negative values
you will probably want to remove the cutoff value entirely to avoid
misconstruing results.</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Microglia_Score1"</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Microglia_Score1"</span>, na_cutoff <span class="op">=</span> <span class="cn">NA</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-14-1.png" width="1248" style="display: block; margin: auto;"></p>
<p>Other times you may actually want to set high na_cutoff value to
enable better interpretation of the range of values in particular
clusters of interest.</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_human_pm</span>, features <span class="op">=</span> <span class="st">"nFeature_RNA"</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_human_pm</span>, features <span class="op">=</span> <span class="st">"nFeature_RNA"</span>, na_cutoff <span class="op">=</span> <span class="fl">6000</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-16-1.png" width="1248" style="display: block; margin: auto;"></p>
</div>
</div>
<div class="section level4">
<h4 id="split-feature-plots">Split Feature Plots<a class="anchor" aria-label="anchor" href="#split-feature-plots"></a>
</h4>
<p><code><a href="https://satijalab.org/seurat/reference/FeaturePlot.html" class="external-link">Seurat::FeaturePlot()</a></code> has additional issues when
splitting by object@meta.data variable.</p>
<ul>
<li>Specifying the number of columns in output is no longer possible
which makes viewing plots from objects with large numbers of variables
difficult.</li>
</ul>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://satijalab.org/seurat/reference/FeaturePlot.html" class="external-link">FeaturePlot</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"P2ry12"</span>, split.by <span class="op">=</span> <span class="st">"orig.ident"</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-17-1.png" alt="*`FeaturePlot()` when using `split.by` outputs with the number of columns equal to the number of levels in meta.data column.*" width="1248"><p class="caption">
<em><code><a href="https://satijalab.org/seurat/reference/FeaturePlot.html" class="external-link">FeaturePlot()</a></code> when using <code>split.by</code> outputs
with the number of columns equal to the number of levels in meta.data
column.</em>
</p>
</div>
<p><strong>FeaturePlot_scCustom solves this issue and allows for setting
the number of columns in FeaturePlots</strong></p>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"P2ry12"</span>, split.by <span class="op">=</span> <span class="st">"sample_id"</span>,</span>
<span>    num_columns <span class="op">=</span> <span class="fl">4</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-18-1.png" alt="*`Split_FeaturePlot()` solves this issue and restores ability to set column number using `ncolumns` parameter.*" width="1248"><p class="caption">
<em><code>Split_FeaturePlot()</code> solves this issue and restores
ability to set column number using <code>ncolumns</code> parameter.</em>
</p>
</div>
</div>
<div class="section level4">
<h4 id="change-the-transparency-of-points">Change the transparency of points<a class="anchor" aria-label="anchor" href="#change-the-transparency-of-points"></a>
</h4>
<p><code>FeaturePlot_scCustom</code> also allows for customization of
the transparency (alpha) of both the points of expressing cells and
non-expressing cells using optional parameters.</p>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/FeaturePlot_scCustom.html">FeaturePlot_scCustom</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Jun"</span>, alpha_exp <span class="op">=</span> <span class="fl">0.75</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-20-1.png" alt="*Example comparing **A.** default `FeaturePlot_scCustom` vs. **B.** plot with alpha of expressing cells adjusted `alpha_exp = 0.55`.*" width="1248"><p class="caption">
<em>Example comparing <strong>A.</strong> default
<code>FeaturePlot_scCustom</code> vs. <strong>B.</strong> plot with
alpha of expressing cells adjusted <code>alpha_exp = 0.55</code>.</em>
</p>
</div>
</div>
<div class="section level4">
<h4 id="density-plots">Density Plots<a class="anchor" aria-label="anchor" href="#density-plots"></a>
</h4>
<p>The <a href="https://github.com/powellgenomicslab/Nebulosa" class="external-link">Nebulosa
package</a> provides really great functions for plotting gene expression
via density plots.</p>
<p>scCustomize provides two functions to extend functionality of these
plots and for ease of plotting “joint” density plots.</p>
<div class="section level5">
<h5 id="custom-color-palettes">Custom color palettes<a class="anchor" aria-label="anchor" href="#custom-color-palettes"></a>
</h5>
<p>Currently Nebulosa only supports plotting using 1 of 5 viridis color
palettes: “viridis”, “magma”, “cividis”, “inferno”, and “plasma”).
<code><a href="../reference/Plot_Density_Custom.html">Plot_Density_Custom()</a></code> changes the default palette to
“magma” and also allows for use of any custom gradient.</p>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Plot_Density_Custom.html">Plot_Density_Custom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Fos"</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/Plot_Density_Custom.html">Plot_Density_Custom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="st">"Fos"</span>, custom_palette <span class="op">=</span> <span class="fu"><a href="https://satijalab.org/seurat/reference/CustomPalette.html" class="external-link">PurpleAndYellow</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-22-1.png" width="960" style="display: block; margin: auto;"></p>
</div>
<div class="section level5">
<h5 id="joint-plots">Joint Plots<a class="anchor" aria-label="anchor" href="#joint-plots"></a>
</h5>
<p>Often user may only want to return the “Joint” density plot when
providing multiple features. <code><a href="../reference/Plot_Density_Joint_Only.html">Plot_Density_Joint_Only()</a></code>
simplifies this requiring only single function and only returns the
joint plot for the features provided.</p>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Plot_Density_Joint_Only.html">Plot_Density_Joint_Only</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Fos"</span>, <span class="st">"Jun"</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-23-1.png" width="576" style="display: block; margin: auto;"></p>
</div>
</div>
<div class="section level4">
<h4 id="dual-assay-plotting">Dual Assay Plotting<a class="anchor" aria-label="anchor" href="#dual-assay-plotting"></a>
</h4>
<p>In certain situations returning a plot from two different assays
within the same object may be advantageous. For instance when object
contains but raw and Cell Bender corrected counts you may want to plot
the same gene from both assays to view the difference. See Cell Bender
Functionality vignette for more info.</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">cell_bender_example</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/qs/man/qread.html" class="external-link">qread</a></span><span class="op">(</span><span class="st">"assets/astro_nuc_seq.qs"</span><span class="op">)</span></span></code></pre></div>
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/FeaturePlot_DualAssay.html">FeaturePlot_DualAssay</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">cell_bender_example</span>, features <span class="op">=</span> <span class="st">"Syt1"</span>, assay1 <span class="op">=</span> <span class="st">"RAW"</span>, assay2 <span class="op">=</span> <span class="st">"RNA"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-26-1.png" width="1248" style="display: block; margin: auto;"></p>
</div>
</div>
<div class="section level3">
<h3 id="non-2d-gene-expression-plots-violin-dot-etc">Non-2D Gene Expression Plots (Violin, Dot, etc)<a class="anchor" aria-label="anchor" href="#non-2d-gene-expression-plots-violin-dot-etc"></a>
</h3>
<div class="section level4">
<h4 id="stacked-violin-plots">Stacked Violin Plots<a class="anchor" aria-label="anchor" href="#stacked-violin-plots"></a>
</h4>
<p>Often plotting many genes simultaneously using Violin plots is
desired. scCustomize provides <code><a href="../reference/Stacked_VlnPlot.html">Stacked_VlnPlot()</a></code> for a more
aesthetic stacked violin plot compared to stacked plots that can be made
using default <code><a href="https://satijalab.org/seurat/reference/VlnPlot.html" class="external-link">Seurat::VlnPlot()</a></code>.<br><em>The original version of this function was written by Ming Tang and
<a href="https://divingintogeneticsandgenomics.rbind.io/post/stacked-violin-plot-for-visualizing-single-cell-data-in-seurat/" class="external-link">posted
on his blog</a>. Function is included with permission and
authorship.</em></p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">gene_list_plot</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"SLC17A7"</span>, <span class="st">"GAD2"</span>, <span class="st">"AQP4"</span>, <span class="st">"MYT1"</span>, <span class="st">"COL1A2"</span>, <span class="st">"CLDN5"</span>, <span class="st">"OPALIN"</span>, <span class="st">"CX3CR1"</span>, <span class="st">"CD3E"</span><span class="op">)</span></span>
<span><span class="va">human_colors_list</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"dodgerblue"</span>, <span class="st">"navy"</span>, <span class="st">"forestgreen"</span>, <span class="st">"darkorange2"</span>, <span class="st">"darkorchid3"</span>, <span class="st">"orchid"</span>,</span>
<span>    <span class="st">"orange"</span>, <span class="st">"gold"</span>, <span class="st">"gray"</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Create Plots</span></span>
<span><span class="fu"><a href="../reference/Stacked_VlnPlot.html">Stacked_VlnPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_human_pm</span>, features <span class="op">=</span> <span class="va">gene_list_plot</span>, x_lab_rotate <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>    colors_use <span class="op">=</span> <span class="va">human_colors_list</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-27-1.png" width="960" style="display: block; margin: auto;"></p>
<div class="section level5">
<h5 id="stacked_vlnplot-also-supports-any-additional-parameters-that-are-part-of-seuratvlnplot">
<code>Stacked_VlnPlot</code> also supports any additional parameters
that are part of <code>Seurat::VlnPlot()</code><a class="anchor" aria-label="anchor" href="#stacked_vlnplot-also-supports-any-additional-parameters-that-are-part-of-seuratvlnplot"></a>
</h5>
<p>For instance splitting plot by meta data feature.</p>
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">sample_colors</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"dodgerblue"</span>, <span class="st">"forestgreen"</span>, <span class="st">"firebrick1"</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Create Plots</span></span>
<span><span class="fu"><a href="../reference/Stacked_VlnPlot.html">Stacked_VlnPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_human_pm</span>, features <span class="op">=</span> <span class="va">gene_list_plot</span>, x_lab_rotate <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>    colors_use <span class="op">=</span> <span class="va">sample_colors</span>, split.by <span class="op">=</span> <span class="st">"orig.ident"</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-28-1.png" alt="*Example plot adding the `split.by` parameter to view expression by sample and cell type.*" width="1248"><p class="caption">
<em>Example plot adding the <code>split.by</code> parameter to view
expression by sample and cell type.</em>
</p>
</div>
</div>
<div class="section level5">
<h5 id="adjust-vertical-plot-spacing">Adjust Vertical Plot Spacing<a class="anchor" aria-label="anchor" href="#adjust-vertical-plot-spacing"></a>
</h5>
<p>Depending on number of genes plotted and user preferences it may be
helpful to change the vertical spacing between plots. This can be done
using the <code>plot_spacing</code> and <code>spacing_unit</code>
parameters.</p>
<div class="sourceCode" id="cb19"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Default plot spacing (plot_spacing = 0.15 and spacing_unit = 'cm')</span></span>
<span><span class="fu"><a href="../reference/Stacked_VlnPlot.html">Stacked_VlnPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"CD3E"</span>, <span class="st">"CD14"</span>, <span class="st">"MS4A1"</span>, <span class="st">"FCER1A"</span>, <span class="st">"PPBP"</span><span class="op">)</span>, x_lab_rotate <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Double the space between plots</span></span>
<span><span class="fu"><a href="../reference/Stacked_VlnPlot.html">Stacked_VlnPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"CD3E"</span>, <span class="st">"CD14"</span>, <span class="st">"MS4A1"</span>, <span class="st">"FCER1A"</span>, <span class="st">"PPBP"</span><span class="op">)</span>, x_lab_rotate <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>    plot_spacing <span class="op">=</span> <span class="fl">0.3</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-30-1.png" width="960" style="display: block; margin: auto;"></p>
</div>
<div class="section level5">
<h5 id="adjusting-plot-size">Adjusting Plot Size<a class="anchor" aria-label="anchor" href="#adjusting-plot-size"></a>
</h5>
<p>Please note that even more so than many other plots you will need to
adjust the height and width of these plots significantly depending on
the number of features and number of identities being plotted.</p>
</div>
<div class="section level5">
<h5 id="stacked_vlnplot-also-supports-plotting-of-objectmeta-data-variables-i-e--mito-or-module-scores-">
<code>Stacked_VlnPlot</code> also supports plotting of
object@meta.data variables (i.e. mito% or module scores).<a class="anchor" aria-label="anchor" href="#stacked_vlnplot-also-supports-plotting-of-objectmeta-data-variables-i-e--mito-or-module-scores-"></a>
</h5>
<div class="sourceCode" id="cb20"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Stacked_VlnPlot.html">Stacked_VlnPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_human_pm</span>, features <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"percent_mito"</span>, <span class="st">"percent_ribo"</span><span class="op">)</span>, x_lab_rotate <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>    colors_use <span class="op">=</span> <span class="va">human_colors_list</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-31-1.png" width="1248" style="display: block; margin: auto;"></p>
</div>
<div class="section level5">
<h5 id="point-size-and-rasterization">Point Size and Rasterization<a class="anchor" aria-label="anchor" href="#point-size-and-rasterization"></a>
</h5>
<p>By default <code>Stacked_VlnPlot</code> sets the <code>pt.size</code>
parameter to 0 to accelerate plotting/rendering which slow down
dramatically depending on size of dataset and number of features
plotted.</p>
<p>If points are still desired then plotting/rendering can be sped up by
using the <code>raster</code> parameter. By default raster will be set
to <code>TRUE</code> if <code>pt.size &gt; 0</code> and
<code>number of cells x number of features &gt; 100,000</code>.</p>
</div>
</div>
<div class="section level4">
<h4 id="custom-vlnplots">Custom VlnPlots<a class="anchor" aria-label="anchor" href="#custom-vlnplots"></a>
</h4>
<p>In addition to <code>Stacked_VlnPlot</code> scCustomize also features
a modified version of Seurat’s <code><a href="https://satijalab.org/seurat/reference/VlnPlot.html" class="external-link">VlnPlot()</a></code>.</p>
<div class="section level5">
<h5 id="vlnplot_sccustom-provides-unified-color-palette-plotting">
<code>VlnPlot_scCustom</code> provides unified color palette
plotting<a class="anchor" aria-label="anchor" href="#vlnplot_sccustom-provides-unified-color-palette-plotting"></a>
</h5>
<div class="sourceCode" id="cb21"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://satijalab.org/seurat/reference/VlnPlot.html" class="external-link">VlnPlot</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="st">"PTPRC"</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/VlnPlot_scCustom.html">VlnPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="st">"PTPRC"</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-33-1.png" alt="***A.** Default `VlnPlot` with ggplot2 default color scheme.  **B.** `VlnPlot_scCustom` shares color palette choice with other scCustomize functions.*" width="1248"><p class="caption">
<em><strong>A.</strong> Default <code>VlnPlot</code> with ggplot2
default color scheme. <strong>B.</strong> <code>VlnPlot_scCustom</code>
shares color palette choice with other scCustomize functions.</em>
</p>
</div>
</div>
<div class="section level5">
<h5 id="support-for-rasterization">Support for Rasterization<a class="anchor" aria-label="anchor" href="#support-for-rasterization"></a>
</h5>
<p>Seurat <code><a href="https://satijalab.org/seurat/reference/VlnPlot.html" class="external-link">VlnPlot()</a></code> supports rasterization but does not
alter it’s plotting behavior by default. Both
<code>Stacked_VlnPlot</code> and <code>VlnPlot_scCustom</code> have a
built in check to automatically rasterize the points if the:
<code>number of cells x number of features &gt; 100,000</code> to
accelerate plotting when vector plots are not necessary.</p>
<p>Rasterization can also be manually turned on or off using the
<code>raster</code> parameter</p>
<div class="sourceCode" id="cb22"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/VlnPlot_scCustom.html">VlnPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="st">"PTPRC"</span>, raster <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/VlnPlot_scCustom.html">VlnPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="st">"PTPRC"</span>, raster <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-35-1.png" alt="***A.** `raster = FALSE`.  **B.** `raster = TRUE`.*" width="1248"><p class="caption">
<em><strong>A.</strong> <code>raster = FALSE</code>. <strong>B.</strong>
<code>raster = TRUE</code>.</em>
</p>
</div>
</div>
<div class="section level5">
<h5 id="further-customization">Further customization<a class="anchor" aria-label="anchor" href="#further-customization"></a>
</h5>
<p>scCustomize <code>VlnPlot_scCustom</code> can be further customized
to display the median value for each idenity or add boxplot on top of
the violin.</p>
<div class="sourceCode" id="cb23"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/VlnPlot_scCustom.html">VlnPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="st">"PTPRC"</span>, plot_median <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span> <span class="op">&amp;</span> <span class="fu"><a href="https://satijalab.org/seurat/reference/SeuratTheme.html" class="external-link">NoLegend</a></span><span class="op">(</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/VlnPlot_scCustom.html">VlnPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="st">"PTPRC"</span>, plot_boxplot <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span> <span class="op">&amp;</span> <span class="fu"><a href="https://satijalab.org/seurat/reference/SeuratTheme.html" class="external-link">NoLegend</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-37-1.png" alt="***A.** Add median value to plot.  **B.** Add boxplot on top of plot.*" width="1248"><p class="caption">
<em><strong>A.</strong> Add median value to plot. <strong>B.</strong>
Add boxplot on top of plot.</em>
</p>
</div>
</div>
</div>
<div class="section level4">
<h4 id="custom-dotplots">Custom DotPlots<a class="anchor" aria-label="anchor" href="#custom-dotplots"></a>
</h4>
<p>Seurat’s <code><a href="https://satijalab.org/seurat/reference/DotPlot.html" class="external-link">DotPlot()</a></code> function is really good but lacks the
ability to provide custom color gradient of more than 2 colors.</p>
<div class="section level5">
<h5 id="dotplot_sccustom-allows-for-plotting-with-custom-gradients-">
<code>DotPlot_scCustom()</code> allows for plotting with custom
gradients.<a class="anchor" aria-label="anchor" href="#dotplot_sccustom-allows-for-plotting-with-custom-gradients-"></a>
</h5>
<div class="sourceCode" id="cb24"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">micro_genes</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"P2ry12"</span>, <span class="st">"Fcrls"</span>, <span class="st">"Trem2"</span>, <span class="st">"Tmem119"</span>, <span class="st">"Cx3cr1"</span>, <span class="st">"Hexb"</span>, <span class="st">"Tgfbr1"</span>, <span class="st">"Sparc"</span>, <span class="st">"P2ry13"</span>,</span>
<span>    <span class="st">"Olfml3"</span>, <span class="st">"Adgrg1"</span>, <span class="st">"C1qa"</span>, <span class="st">"C1qb"</span>, <span class="st">"C1qc"</span>, <span class="st">"Csf1r"</span>, <span class="st">"Fcgr3"</span>, <span class="st">"Ly86"</span>, <span class="st">"Laptm5"</span><span class="op">)</span></span>
<span></span>
<span><span class="fu"><a href="https://satijalab.org/seurat/reference/DotPlot.html" class="external-link">DotPlot</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="va">micro_genes</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">6</span><span class="op">]</span>, cols <span class="op">=</span> <span class="va">viridis_plasma_dark_high</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/DotPlot_scCustom.html">DotPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="va">micro_genes</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">6</span><span class="op">]</span>, colors_use <span class="op">=</span> <span class="va">viridis_plasma_dark_high</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-39-1.png" alt="***A.** Default `DotPlot` only takes the first few colors when a gradient is provided.  **B.** `DotPlot_scCustom` allows for use of gradients in full while maintaining visualization.*" width="1248"><p class="caption">
<em><strong>A.</strong> Default <code>DotPlot</code> only takes the
first few colors when a gradient is provided. <strong>B.</strong>
<code>DotPlot_scCustom</code> allows for use of gradients in full while
maintaining visualization.</em>
</p>
</div>
</div>
<div class="section level5">
<h5 id="dotplot_sccustom-also-contains-additional-parameters-for-easy-manipulations-of-axes-for-better-plotting-">
<code>DotPlot_scCustom()</code> also contains additional parameters
for easy manipulations of axes for better plotting.<a class="anchor" aria-label="anchor" href="#dotplot_sccustom-also-contains-additional-parameters-for-easy-manipulations-of-axes-for-better-plotting-"></a>
</h5>
<p>These allow for:</p>
<ul>
<li>
<code>x_lab_rotate</code> rotating x-axis text Default is
FALSE.</li>
<li>
<code>y_lab_rotate</code> rotating y-axis text Default is
FALSE.</li>
<li>
<code>flip_axes</code> flip the axes. Default is FALSE.</li>
<li>
<code>remove_axis_titles</code> remove the x- and y-axis labels.
Default is TRUE</li>
</ul>
<div class="sourceCode" id="cb25"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/DotPlot_scCustom.html">DotPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="va">micro_genes</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">6</span><span class="op">]</span>, x_lab_rotate <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/DotPlot_scCustom.html">DotPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="va">micro_genes</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">6</span><span class="op">]</span>, y_lab_rotate <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/DotPlot_scCustom.html">DotPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="va">micro_genes</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">6</span><span class="op">]</span>, flip_axes <span class="op">=</span> <span class="cn">T</span>,</span>
<span>    x_lab_rotate <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/DotPlot_scCustom.html">DotPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="va">micro_genes</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">6</span><span class="op">]</span>, flip_axes <span class="op">=</span> <span class="cn">T</span>,</span>
<span>    remove_axis_titles <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-41-1.png" alt="***A.** Rotate x-axis text, **B.** Rotate y-axis text, **C.** flip axes and rotate x-axis text, and **D.** Add axis labels (removed by default).*" width="1248"><p class="caption">
<em><strong>A.</strong> Rotate x-axis text, <strong>B.</strong> Rotate
y-axis text, <strong>C.</strong> flip axes and rotate x-axis text, and
<strong>D.</strong> Add axis labels (removed by default).</em>
</p>
</div>
</div>
</div>
<div class="section level4">
<h4 id="clustered-dotplots">Clustered DotPlots<a class="anchor" aria-label="anchor" href="#clustered-dotplots"></a>
</h4>
<p>For a more advanced take on the <code>DotPlot</code> scCustomize
contains a separate function <code><a href="../reference/Clustered_DotPlot.html">Clustered_DotPlot()</a></code>. This
function allows for clustering of both gene expression patterns and
identities in the final plot. <em>The original version of this function
was written by Ming Tang and <a href="https://divingintogeneticsandgenomics.rbind.io/post/clustered-dotplot-for-single-cell-rnaseq/" class="external-link">posted
on his blog</a>. Function is included with permission, authorship, and
assistance.</em></p>
<div class="sourceCode" id="cb26"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Find markers and limit to those expressed in greater than 75% of target population</span></span>
<span><span class="va">all_markers</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://satijalab.org/seurat/reference/FindAllMarkers.html" class="external-link">FindAllMarkers</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">pbmc</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span>    <span class="fu"><a href="../reference/Add_Pct_Diff.html">Add_Pct_Diff</a></span><span class="op">(</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span></span>
<span>    <span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html" class="external-link">filter</a></span><span class="op">(</span><span class="va">pct_diff</span> <span class="op">&gt;</span> <span class="fl">0.6</span><span class="op">)</span></span>
<span></span>
<span><span class="va">top_markers</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Extract_Top_Markers.html">Extract_Top_Markers</a></span><span class="op">(</span>marker_dataframe <span class="op">=</span> <span class="va">all_markers</span>, num_genes <span class="op">=</span> <span class="fl">7</span>, named_vector <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>    make_unique <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span></span>
<span><span class="fu"><a href="../reference/Clustered_DotPlot.html">Clustered_DotPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="va">top_markers</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-44-1.png" width="960" style="display: block; margin: auto;"></p>
<div class="section level5">
<h5 id="cluster-plot-on-gene-expression-patterns">Cluster Plot on Gene Expression Patterns<a class="anchor" aria-label="anchor" href="#cluster-plot-on-gene-expression-patterns"></a>
</h5>
<p>By default <code>Clustered_DotPlot</code> performs k-means clustering
with k value set to 1. However, users can change this value to enable
better visualization of expression patterns.</p>
<div class="sourceCode" id="cb27"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Clustered_DotPlot.html">Clustered_DotPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="va">top_markers</span>, k <span class="op">=</span> <span class="fl">8</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-47-1.png" width="960" style="display: block; margin: auto;"></p>
</div>
<div class="section level5">
<h5 id="clustered_dotplot-split-by-additional-grouping-variable">Clustered_DotPlot() split by additional grouping variable<a class="anchor" aria-label="anchor" href="#clustered_dotplot-split-by-additional-grouping-variable"></a>
</h5>
<p><code>Clustered_DotPlot</code> can now plot with additional grouping
variable provided to <code>split.by</code> parameter.</p>
<div class="sourceCode" id="cb28"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Clustered_DotPlot.html">Clustered_DotPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Fos"</span>, <span class="st">"Jun"</span>, <span class="st">"Egr1"</span>, <span class="st">"Aif1"</span>,</span>
<span>    <span class="st">"P2ry12"</span>, <span class="st">"Tmem119"</span><span class="op">)</span>, split.by <span class="op">=</span> <span class="st">"Transcription_Method"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-50-1.png" width="960" style="display: block; margin: auto;"></p>
<p>However, you’ll notice that the labels on the bottom get cutoff on
the left-hand side of the plot. There are two solutions to this.</p>
<p>Keep bottom labels rotated but add extra white-space padding on
left</p>
<div class="sourceCode" id="cb29"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Clustered_DotPlot.html">Clustered_DotPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Fos"</span>, <span class="st">"Jun"</span>, <span class="st">"Egr1"</span>, <span class="st">"Aif1"</span>,</span>
<span>    <span class="st">"P2ry12"</span>, <span class="st">"Tmem119"</span><span class="op">)</span>, split.by <span class="op">=</span> <span class="st">"Transcription_Method"</span>, plot_padding <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-53-1.png" width="960" style="display: block; margin: auto;"></p>
<p>Or simply remove the bottom label text rotation</p>
<div class="sourceCode" id="cb30"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Clustered_DotPlot.html">Clustered_DotPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, features <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"Fos"</span>, <span class="st">"Jun"</span>, <span class="st">"Egr1"</span>, <span class="st">"Aif1"</span>,</span>
<span>    <span class="st">"P2ry12"</span>, <span class="st">"Tmem119"</span><span class="op">)</span>, split.by <span class="op">=</span> <span class="st">"Transcription_Method"</span>, x_lab_rotate <span class="op">=</span> <span class="fl">90</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-56-1.png" width="960" style="display: block; margin: auto;"></p>
</div>
<div class="section level5">
<h5 id="clustered_dotplot-k-means-clustering-optional-parameters">Clustered_DotPlot() k-means Clustering Optional Parameters<a class="anchor" aria-label="anchor" href="#clustered_dotplot-k-means-clustering-optional-parameters"></a>
</h5>
<p><strong>Determining Optimal k Value</strong><br>
There are many methods that can be used to aid in determining an optimal
value for k in k-means clustering. One of the simplest is to the look at
the elbow in sum of squares error plot. By default
<code>Clustered_DotPlot</code> will return this plot when using the
function. However, it can be turned off by setting
<code>plot_km_elbow = FALSE</code>.
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-57-1.png" width="480" style="display: block; margin: auto;"></p>
<p>The number of k values plotted must be 1 less than number of
features. Default is to plot 20 values but users can customize number of
k values plotted using <code>elbow_kmax</code> parameter.</p>
<p><strong>Consensus k-means Clustering</strong><br>
By default <code>Clustered_DotPlot</code> uses consensus k-means
clustering with 1000 repeats for both the columns and rows. However,
user can reduce or increase these values as desired by supplying new
value to either or both of
<code>row_km_repeats</code>/<code>column_km_repeats</code></p>
</div>
<div class="section level5">
<h5 id="clustered_dotplot-expression-scale-optional-parameters">Clustered_DotPlot() Expression Scale Optional Parameters<a class="anchor" aria-label="anchor" href="#clustered_dotplot-expression-scale-optional-parameters"></a>
</h5>
<p>There are a number of optional parameters that can be modified by
user depending on the desired resulting plot.</p>
<ul>
<li>
<code>colors_use_exp</code> to provide custom color scale</li>
<li>
<code>exp_color_min</code>/<code>exp_color_max</code> can be used to
clip the min and max values on the expression scale.</li>
<li>
<code>print_exp_quantiles</code> can be set to TRUE to print the
expression quantiles to aid in setting new
<code>exp_color_min</code>/<code>exp_color_max</code>.</li>
<li>
<code>exp_color_middle</code> can be used to change what value is
used for the middle of the color scale. By default is set to the middle
of <code>exp_color_min</code>/<code>exp_color_max</code> but can be
modified if a skewed visualization is desired.</li>
</ul>
<div class="sourceCode" id="cb31"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Clustered_DotPlot.html">Clustered_DotPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="va">top_markers</span>, k <span class="op">=</span> <span class="fl">8</span>, print_exp_quantiles <span class="op">=</span> <span class="cn">T</span><span class="op">)</span></span></code></pre></div>
<div class="sourceCode" id="cb32"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb32-1"><a href="#cb32-1" tabindex="-1"></a>Quantiles of gene expression data are<span class="sc">:</span></span>
<span id="cb32-2"><a href="#cb32-2" tabindex="-1"></a>       <span class="dv">10</span><span class="sc">%        50%</span>        <span class="dv">90</span><span class="sc">%        99%</span> </span>
<span id="cb32-3"><a href="#cb32-3" tabindex="-1"></a><span class="sc">-</span><span class="fl">0.6555988</span> <span class="sc">-</span><span class="fl">0.3595223</span>  <span class="fl">1.7742718</span>  <span class="fl">2.6666597</span></span></code></pre></div>
<p>Here we can adjust the expression clipping based on the range of the
data in this specific dataset and list of features and change the color
scale to use <code><a href="https://satijalab.org/seurat/reference/CustomPalette.html" class="external-link">Seurat::PurpleAndYellow()</a></code></p>
<div class="sourceCode" id="cb33"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Clustered_DotPlot.html">Clustered_DotPlot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, features <span class="op">=</span> <span class="va">top_markers</span>, k <span class="op">=</span> <span class="fl">8</span>, exp_color_min <span class="op">=</span> <span class="op">-</span><span class="fl">1</span>, exp_color_max <span class="op">=</span> <span class="fl">2</span>,</span>
<span>    colors_use_exp <span class="op">=</span> <span class="fu"><a href="https://satijalab.org/seurat/reference/CustomPalette.html" class="external-link">PurpleAndYellow</a></span><span class="op">(</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-62-1.png" width="960" style="display: block; margin: auto;"></p>
</div>
<div class="section level5">
<h5 id="clustered_dotplot-other-optional-parameters">Clustered_DotPlot() Other Optional Parameters<a class="anchor" aria-label="anchor" href="#clustered_dotplot-other-optional-parameters"></a>
</h5>
<ul>
<li>
<code>colors_use_idents</code> Colors to use for the identities
(columns) plotted.<br>
</li>
<li>
<code>x_lab_rotate</code> Logical or Integer. Default is TRUE (45
degree column label rotation). FALSE (0 degree rotation). Integer for
custom text rotation value.<br>
</li>
<li>
<code>row_label_size</code> Change size of row text (gene
symbols).<br>
</li>
<li>
<code>raster</code> Whether to rasterize the plot (faster and
smaller file size). Default is FALSE.</li>
</ul>
</div>
</div>
<div class="section level4">
<h4 id="featurescater-plots">FeatureScater Plots<a class="anchor" aria-label="anchor" href="#featurescater-plots"></a>
</h4>
<p>The scCustomize function <code><a href="../reference/FeatureScatter_scCustom.html">FeatureScatter_scCustom()</a></code> is a
slightly modified version of <code><a href="https://satijalab.org/seurat/reference/FeatureScatter.html" class="external-link">Seurat::FeatureScatter()</a></code> with
some different default settings and parameter options.</p>
<p><code><a href="../reference/FeatureScatter_scCustom.html">FeatureScatter_scCustom()</a></code> plots can be very useful when
comparing between two genes/features or comparing module scores. By
default scCustomize version sets <code>shuffle = TRUE</code> to ensure
that points are not hidden due to order of plotting.</p>
<div class="sourceCode" id="cb34"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Create Plots</span></span>
<span><span class="fu"><a href="../reference/FeatureScatter_scCustom.html">FeatureScatter_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, feature1 <span class="op">=</span> <span class="st">"exAM_Score1"</span>, feature2 <span class="op">=</span> <span class="st">"Microglia_Score1"</span>,</span>
<span>    colors_use <span class="op">=</span> <span class="va">mouse_colors</span>, group.by <span class="op">=</span> <span class="st">"ident"</span>, num_columns <span class="op">=</span> <span class="fl">2</span>, pt.size <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-63-1.png" width="1248" style="display: block; margin: auto;"></p>
<div class="section level5">
<h5 id="split-featurescatter-plots">Split FeatureScatter Plots<a class="anchor" aria-label="anchor" href="#split-featurescatter-plots"></a>
</h5>
<p>scCustomize previously contained function
<code>Split_FeatureScatter</code> as Seurat’s plot lacked that
functionality. However, that is now present and
<code>Split_FeatureScatter</code> has therefore been deprecated and it’s
functionality moved within <code>FeatureScatter_scCustom</code>.</p>
<p><code><a href="../reference/FeatureScatter_scCustom.html">FeatureScatter_scCustom()</a></code> contains two options for
splitting plots (similar to <code>DimPlot_scCustom</code>. The default
is to return each plot with their own x and y axes, which has a number
of advantages (see <code>DimPlot_scCustom</code> section).</p>
<div class="sourceCode" id="cb35"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Create Plots</span></span>
<span><span class="fu"><a href="../reference/FeatureScatter_scCustom.html">FeatureScatter_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, feature1 <span class="op">=</span> <span class="st">"exAM_Score1"</span>, feature2 <span class="op">=</span> <span class="st">"Microglia_Score1"</span>,</span>
<span>    colors_use <span class="op">=</span> <span class="va">mouse_colors</span>, split.by <span class="op">=</span> <span class="st">"Transcription_Method"</span>, group.by <span class="op">=</span> <span class="st">"ident"</span>, num_columns <span class="op">=</span> <span class="fl">2</span>,</span>
<span>    pt.size <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-64-1.png" width="1248" style="display: block; margin: auto;"></p>
</div>
</div>
</div>
<div class="section level3">
<h3 id="dimplots-plot-meta-data-in-2d-space-pcatsneumap">DimPlots: Plot Meta Data in 2D Space (PCA/tSNE/UMAP)<a class="anchor" aria-label="anchor" href="#dimplots-plot-meta-data-in-2d-space-pcatsneumap"></a>
</h3>
<p>scCustomize has a few functions that improve on the default plotting
options available in Seurat</p>
<div class="section level4">
<h4 id="dimplots">DimPlots<a class="anchor" aria-label="anchor" href="#dimplots"></a>
</h4>
<p>The scCustomize function <code><a href="../reference/DimPlot_scCustom.html">DimPlot_scCustom()</a></code> is a
slightly modified version of <code><a href="https://satijalab.org/seurat/reference/DimPlot.html" class="external-link">Seurat::DimPlot()</a></code> with some
different default settings and parameter options.</p>
<div class="section level5">
<h5 id="new-default-color-palettes">New default color palettes<a class="anchor" aria-label="anchor" href="#new-default-color-palettes"></a>
</h5>
<p>The default ggplot2 hue palette becomes very hard to distinguish
between at even a moderate number of clusters for a scRNA-seq
experiment. scCustomize’s function <code>DimPlot_scCustom</code> sets
new default color palettes:</p>
<ul>
<li>If less than or equal to 36 groups plotted then the “polychrome”
palette will be used.</li>
<li>If more than 36 groups the “varibow” palette will be used with
<code>shuffle_pal = TRUE</code>.</li>
<li>If user wants to use ggplot2 hue palette then set parameter
<code>ggplot_default_colors = TRUE</code>.</li>
</ul>
<p>To best demonstrate rationale for this I’m going to use
over-clustered version of the <code>marsh_mouse_micro</code> object.</p>
<div class="sourceCode" id="cb36"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://satijalab.org/seurat/reference/DimPlot.html" class="external-link">DimPlot</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">marsh_mouse_over</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/DimPlot_scCustom.html">DimPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_over</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-67-1.png" alt="*`DimPlot_scCustom` also sets `label = TRUE` if `group.by = NULL` by default.*" width="1248"><p class="caption">
<em><code>DimPlot_scCustom</code> also sets <code>label = TRUE</code> if
<code>group.by = NULL</code> by default.</em>
</p>
</div>
</div>
<div class="section level5">
<h5 id="shuffle-points">Shuffle Points<a class="anchor" aria-label="anchor" href="#shuffle-points"></a>
</h5>
<p>By default Seurat’s <code><a href="https://satijalab.org/seurat/reference/DimPlot.html" class="external-link">DimPlot()</a></code> plots each group on top of
the next which can make plots harder to interpret.
<code>DimPlot_scCustom</code> sets <code>shuffle = TRUE</code> by
default as I believe this setting is more often the visualization that
provides the most clarity.</p>
<p>Here is example when plotting by donor in the human dataset to
determine how well the dataset integration worked.</p>
<div class="sourceCode" id="cb37"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://satijalab.org/seurat/reference/DimPlot.html" class="external-link">DimPlot</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">marsh_human_pm</span>, group.by <span class="op">=</span> <span class="st">"sample_id"</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/DimPlot_scCustom.html">DimPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_human_pm</span>, group.by <span class="op">=</span> <span class="st">"sample_id"</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-69-1.png" alt="***A.** Cannot tell how well integrated the samples are due to plotting one on top of the other.  **B.** Default plot using scCustomize `DimPlot_scCustom`.*" width="1248"><p class="caption">
<em><strong>A.</strong> Cannot tell how well integrated the samples are
due to plotting one on top of the other. <strong>B.</strong> Default
plot using scCustomize <code>DimPlot_scCustom</code>.</em>
</p>
</div>
</div>
<div class="section level5">
<h5 id="split-dimplots">Split DimPlots<a class="anchor" aria-label="anchor" href="#split-dimplots"></a>
</h5>
<p>When plotting a split plot <code><a href="https://satijalab.org/seurat/reference/DimPlot.html" class="external-link">Seurat::DimPlot()</a></code> simplifies
the axes by implementing shared axes depending on the number of columns
specified.</p>
<div class="sourceCode" id="cb38"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://satijalab.org/seurat/reference/DimPlot.html" class="external-link">DimPlot</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">pbmc</span>, split.by <span class="op">=</span> <span class="st">"treatment"</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://satijalab.org/seurat/reference/DimPlot.html" class="external-link">DimPlot</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">pbmc</span>, split.by <span class="op">=</span> <span class="st">"sample_id"</span>, ncol <span class="op">=</span> <span class="fl">4</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-71-1.png" alt="***A.** The default Seurat split.by looks ok when plots are all present on single row.  **B.** However, the visualization isn't so good when you starting wrapping plots into multiple rows.*" width="1248"><p class="caption">
<em><strong>A.</strong> The default Seurat split.by looks ok when plots
are all present on single row. <strong>B.</strong> However, the
visualization isn’t so good when you starting wrapping plots into
multiple rows.</em>
</p>
</div>
<p>By default when using <code>split.by</code> with
<code>DimPlot_scCustom</code> the layout is returned with an axes for
each plot to make visualization of large numbers of splits easier.</p>
<div class="sourceCode" id="cb39"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/DimPlot_scCustom.html">DimPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, split.by <span class="op">=</span> <span class="st">"treatment"</span>, num_columns <span class="op">=</span> <span class="fl">4</span>, repel <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<div class="figure">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-73-1.png" alt="*Simplified visualization without having to think about the number of variables that are being plotted.*" width="1248"><p class="caption">
<em>Simplified visualization without having to think about the number of
variables that are being plotted.</em>
</p>
</div>
<p>Can also return to the default Seurat method of splitting plots while
maintaining all of the other modifications in
<code>DimPlot_scCustom</code> by supplying
<code>split_seurat = TRUE</code></p>
<div class="sourceCode" id="cb40"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/DimPlot_scCustom.html">DimPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, split.by <span class="op">=</span> <span class="st">"treatment"</span>, num_columns <span class="op">=</span> <span class="fl">4</span>, repel <span class="op">=</span> <span class="cn">TRUE</span>, split_seurat <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-74-1.png" width="1248"></p>
</div>
<div class="section level5">
<h5 id="figure-plotting">Figure Plotting<a class="anchor" aria-label="anchor" href="#figure-plotting"></a>
</h5>
<p>Some times when creating plots for figures it is desirable to remove
the axes from the plot and simply add an axis legend. To do this with
<code>DimPlot_scCustom</code> simply set
<code>figure_plot = TRUE</code>.</p>
<div class="sourceCode" id="cb41"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/DimPlot_scCustom.html">DimPlot_scCustom</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, figure_plot <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-76-1.png" width="576"></p>
</div>
</div>
<div class="section level4">
<h4 id="highlight-clusters">Highlight Cluster(s)<a class="anchor" aria-label="anchor" href="#highlight-clusters"></a>
</h4>
<p>Even with an optimized color palette it can still be difficult to
determine the boundaries of clusters when plotting all clusters at
once.<br>
scCustomize provides easy of use function
<code><a href="../reference/Cluster_Highlight_Plot.html">Cluster_Highlight_Plot()</a></code> to highlight a select cluster or
clusters vs. the remainder of cells to determine where they lie on the
plot.<br><em>NOTE: While named <code>Cluster_Highlight_Plot</code> this function
will simply pull from seurat_object@active.ident slot which may or may
not be cluster results depending on user settings. For creating
highlight plots of meta data variables see next section on
<code>Meta_Highlight_Plot</code>.</em></p>
<div class="sourceCode" id="cb42"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Cluster_Highlight_Plot.html">Cluster_Highlight_Plot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_over</span>, cluster_name <span class="op">=</span> <span class="st">"7"</span>, highlight_color <span class="op">=</span> <span class="st">"navy"</span>,</span>
<span>    background_color <span class="op">=</span> <span class="st">"lightgray"</span><span class="op">)</span></span>
<span></span>
<span><span class="fu"><a href="../reference/Cluster_Highlight_Plot.html">Cluster_Highlight_Plot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_over</span>, cluster_name <span class="op">=</span> <span class="st">"8"</span>, highlight_color <span class="op">=</span> <span class="st">"forestgreen"</span>,</span>
<span>    background_color <span class="op">=</span> <span class="st">"lightgray"</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-78-1.png" alt="*`Cluster_Highlight_Plot` takes identity or vector of identities and plots them in front of remaining unselected cells.*" width="1248"><p class="caption">
<em><code>Cluster_Highlight_Plot</code> takes identity or vector of
identities and plots them in front of remaining unselected cells.</em>
</p>
</div>
<div class="section level5">
<h5 id="highlight-2-clusters-in-the-same-plot">Highlight 2+ clusters in the same plot<a class="anchor" aria-label="anchor" href="#highlight-2-clusters-in-the-same-plot"></a>
</h5>
<p><code><a href="../reference/Cluster_Highlight_Plot.html">Cluster_Highlight_Plot()</a></code> also supports the ability to
plot multiple identities in the same plot.</p>
<div class="sourceCode" id="cb43"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Cluster_Highlight_Plot.html">Cluster_Highlight_Plot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_over</span>, cluster_name <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"7"</span>, <span class="st">"8"</span><span class="op">)</span>, highlight_color <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"navy"</span>,</span>
<span>    <span class="st">"forestgreen"</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-80-1.png" width="576"></p>
<p><em>NOTE: If no value is provided to <code>highlight_color</code>
then all clusters provided to <code>cluster_name</code> will be plotted
using single default color (navy).</em></p>
</div>
</div>
<div class="section level4">
<h4 id="highlight-meta-data">Highlight Meta Data<a class="anchor" aria-label="anchor" href="#highlight-meta-data"></a>
</h4>
<p>scCustomize also contains an analogous function
<code><a href="../reference/Meta_Highlight_Plot.html">Meta_Highlight_Plot()</a></code> that allows for quick highlight plots
of any valid @meta.data variable. Meta data variables must be one of
class(): “factor”, “character”, or “logical” to be highlighted.<br><em>Numeric variables representing things like “batch” can be converted
using <code>as.character</code> or <code>as.factor</code> first to allow
for plotting.</em></p>
<div class="sourceCode" id="cb44"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Meta_Highlight_Plot.html">Meta_Highlight_Plot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, meta_data_column <span class="op">=</span> <span class="st">"Transcription_Method"</span>,</span>
<span>    meta_data_highlight <span class="op">=</span> <span class="st">"ENZYMATIC_NONE"</span>, highlight_color <span class="op">=</span> <span class="st">"firebrick"</span>, background_color <span class="op">=</span> <span class="st">"lightgray"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-81-1.png" width="576" style="display: block; margin: auto;"></p>
<div class="section level5">
<h5 id="highlight-2-factor-levels-in-the-same-plot">Highlight 2+ factor levels in the same plot<a class="anchor" aria-label="anchor" href="#highlight-2-factor-levels-in-the-same-plot"></a>
</h5>
<p><code><a href="../reference/Meta_Highlight_Plot.html">Meta_Highlight_Plot()</a></code> also supports plotting two or more
levels from the same meta data column in the same plot, similar to
plotting multiple identities with
<code><a href="../reference/Cluster_Highlight_Plot.html">Cluster_Highlight_Plot()</a></code></p>
<div class="sourceCode" id="cb45"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/Meta_Highlight_Plot.html">Meta_Highlight_Plot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, meta_data_column <span class="op">=</span> <span class="st">"Transcription_Method"</span>,</span>
<span>    meta_data_highlight <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"ENZYMATIC_NONE"</span>, <span class="st">"DOUNCE_NONE"</span><span class="op">)</span>, highlight_color <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"firebrick"</span>, <span class="st">"dodgerblue"</span><span class="op">)</span>,</span>
<span>    background_color <span class="op">=</span> <span class="st">"lightgray"</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-82-1.png" width="576" style="display: block; margin: auto;"></p>
</div>
</div>
<div class="section level4">
<h4 id="highlight-cells">Highlight Cells<a class="anchor" aria-label="anchor" href="#highlight-cells"></a>
</h4>
<p>Sometimes the cells that you want to highlight on a plot may not be
represented by an active.ident or meta.data column. In this scenario you
can use <code>Cell_Highlight_Plot</code>.</p>
<p><em>NOTE: Values of cell names provided to
<code>cells_highlight</code> parameter must be a named list.</em></p>
<p>Let’s say we want to highlight cells with expression of
<em>MS4A1</em> above certain threshold.</p>
<div class="sourceCode" id="cb46"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Get cell names</span></span>
<span><span class="va">MS4A1</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/SeuratObject/man/WhichCells.html" class="external-link">WhichCells</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">pbmc</span>, expression <span class="op">=</span> <span class="va">MS4A1</span> <span class="op">&gt;</span> <span class="fl">3</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Make into list</span></span>
<span><span class="va">cells</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span>MS4A1 <span class="op">=</span> <span class="va">MS4A1</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Plot</span></span>
<span><span class="fu"><a href="../reference/Cell_Highlight_Plot.html">Cell_Highlight_Plot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, cells_highlight <span class="op">=</span> <span class="va">cells</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-84-1.png" width="576" style="display: block; margin: auto;"></p>
<div class="section level5">
<h5 id="highlight-2-sets-of-cells-in-the-same-plot">Highlight 2+ sets of cells in the same plot<a class="anchor" aria-label="anchor" href="#highlight-2-sets-of-cells-in-the-same-plot"></a>
</h5>
<p><code><a href="../reference/Cell_Highlight_Plot.html">Cell_Highlight_Plot()</a></code> also supports plotting two or more
sets of cells in the same plot, similar to plotting multiple identities
with
<code><a href="../reference/Cluster_Highlight_Plot.html">Cluster_Highlight_Plot()</a></code>/<code><a href="../reference/Meta_Highlight_Plot.html">Meta_Highlight_Plot()</a></code>.</p>
<div class="sourceCode" id="cb47"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Get cell names and make list</span></span>
<span><span class="va">MS4A1</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/SeuratObject/man/WhichCells.html" class="external-link">WhichCells</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">pbmc</span>, expression <span class="op">=</span> <span class="va">MS4A1</span> <span class="op">&gt;</span> <span class="fl">3</span><span class="op">)</span></span>
<span><span class="va">GZMB</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/SeuratObject/man/WhichCells.html" class="external-link">WhichCells</a></span><span class="op">(</span>object <span class="op">=</span> <span class="va">pbmc</span>, expression <span class="op">=</span> <span class="va">GZMB</span> <span class="op">&gt;</span> <span class="fl">3</span><span class="op">)</span></span>
<span></span>
<span><span class="va">cells</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span>MS4A1 <span class="op">=</span> <span class="va">MS4A1</span>, GZMB <span class="op">=</span> <span class="va">GZMB</span><span class="op">)</span></span>
<span><span class="co"># Plot</span></span>
<span><span class="fu"><a href="../reference/Cell_Highlight_Plot.html">Cell_Highlight_Plot</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, cells_highlight <span class="op">=</span> <span class="va">cells</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-86-1.png" width="576" style="display: block; margin: auto;"></p>
</div>
</div>
<div class="section level4">
<h4 id="dimplot-layout-plots">DimPlot Layout Plots<a class="anchor" aria-label="anchor" href="#dimplot-layout-plots"></a>
</h4>
<p>Sometimes can be beneficial to create layouts where there is no
grouping variable and plots are simply colored by the split
variable.</p>
<div class="sourceCode" id="cb48"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/DimPlot_All_Samples.html">DimPlot_All_Samples</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">pbmc</span>, meta_data_column <span class="op">=</span> <span class="st">"sample_id"</span>, num_col <span class="op">=</span> <span class="fl">3</span>, pt.size <span class="op">=</span> <span class="fl">0.5</span><span class="op">)</span></span></code></pre></div>
<div class="figure" style="text-align: center">
<img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-87-1.png" alt="*Visualize all samples in simple plot layout.*" width="1248"><p class="caption">
<em>Visualize all samples in simple plot layout.</em>
</p>
</div>
<p>Can unique color each plot by providing a vector of colors instead of
single value</p>
<div class="sourceCode" id="cb49"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="../reference/DimPlot_All_Samples.html">DimPlot_All_Samples</a></span><span class="op">(</span>seurat_object <span class="op">=</span> <span class="va">marsh_mouse_micro</span>, meta_data_column <span class="op">=</span> <span class="st">"Transcription"</span>, num_col <span class="op">=</span> <span class="fl">2</span>,</span>
<span>    pt.size <span class="op">=</span> <span class="fl">0.5</span>, color <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"firebrick3"</span>, <span class="st">"dodgerblue3"</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<p><img src="Gene_Expression_Plotting_files/figure-html/unnamed-chunk-88-1.png" width="1248" style="display: block; margin: auto;"></p>
</div>
</div>
</div>
  </div>

  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">

        <nav id="toc" data-toggle="toc"><h2 data-toc-skip>Contents</h2>
    </nav>
</div>

</div>



      <footer><div class="copyright">
  <p></p>
<p>Developed by Samuel Marsh.</p>
</div>

<div class="pkgdown">
  <p></p>
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.7.</p>
</div>

      </footer>
</div>

  


  

  </body>
</html>
