<metaproperty="og:title"content="PCA biplot with <code>ggplot2</code> — ggplot_pca"/>
<metaproperty="og:description"content="This function is to produce a ggplot2 variant of a so-called biplot for PCA (principal component analysis), but is more flexible and more appealing than the base R biplot() function."/>
<p>This function is to produce a <code>ggplot2</code> variant of a so-called <ahref='https://en.wikipedia.org/wiki/Biplot'>biplot</a> for PCA (principal component analysis), but is more flexible and more appealing than the base <spanstyle="R">R</span><code><ahref='https://rdrr.io/r/stats/biplot.html'>biplot()</a></code> function.</p>
<td><p>an object returned by <code><ahref='pca.html'>pca()</a></code>, <code><ahref='https://rdrr.io/r/stats/prcomp.html'>prcomp()</a></code> or <code><ahref='https://rdrr.io/r/stats/princomp.html'>princomp()</a></code></p></td>
</tr>
<tr>
<th>choices</th>
<td><p>length 2 vector specifying the components to plot. Only the default
is a biplot in the strict sense.</p></td>
</tr>
<tr>
<th>scale</th>
<td><p>The variables are scaled by <code>lambda ^ scale</code> and the
observations are scaled by <code>lambda ^ (1-scale)</code> where
<code>lambda</code> are the singular values as computed by
<code><ahref='https://rdrr.io/r/stats/princomp.html'>princomp</a></code>. Normally <code>0 <= scale <= 1</code>, and a warning
will be issued if the specified <code>scale</code> is outside this range.</p></td>
</tr>
<tr>
<th>labels</th>
<td><p>an optional vector of labels for the observations. If set, the labels will be placed below their respective points. When using the <code><ahref='pca.html'>pca()</a></code> function as input for <code>x</code>, this will be determined automatically based on the attribute <code>non_numeric_cols</code>, see <code><ahref='pca.html'>pca()</a></code>.</p></td>
</tr>
<tr>
<th>labels_textsize</th>
<td><p>the size of the text used for the labels</p></td>
</tr>
<tr>
<th>labels_text_placement</th>
<td><p>adjustment factor the placement of the variable names (<code>>=1</code> means further away from the arrow head)</p></td>
</tr>
<tr>
<th>groups</th>
<td><p>an optional vector of groups for the labels, with the same length as <code>labels</code>. If set, the points and labels will be coloured according to these groups. When using the <code><ahref='pca.html'>pca()</a></code> function as input for <code>x</code>, this will be determined automatically based on the attribute <code>non_numeric_cols</code>, see <code><ahref='pca.html'>pca()</a></code>.</p></td>
</tr>
<tr>
<th>ellipse</th>
<td><p>a logical to indicate whether a normal data ellipse should be drawn for each group (set with <code>groups</code>)</p></td>
</tr>
<tr>
<th>ellipse_prob</th>
<td><p>statistical size of the ellipse in normal probability</p></td>
</tr>
<tr>
<th>ellipse_size</th>
<td><p>the size of the ellipse line</p></td>
</tr>
<tr>
<th>ellipse_alpha</th>
<td><p>the alpha (transparency) of the ellipse line</p></td>
<p>The <code>ggplot_pca()</code> function is based on the <code>ggbiplot()</code> function from the <code>ggbiplot</code> package by Vince Vu, as found on GitHub: <ahref='https://github.com/vqv/ggbiplot'>https://github.com/vqv/ggbiplot</a> (retrieved: 2 March 2020, their latest commit: <ahref='https://github.com/vqv/ggbiplot/commit/7325e880485bea4c07465a0304c470608fffb5d9'><code>7325e88</code></a>; 12 February 2015).</p>
<p>As per their GPL-2 licence that demands documentation of code changes, the changes made based on the source code were:</p><ol>
<li><p>Rewritten code to remove the dependency on packages <code>plyr</code>, <code>scales</code> and <code>grid</code></p></li>
<li><p>Parametrised more options, like arrow and ellipse settings</p></li>
<li><p>Added total amount of explained variance as a caption in the plot</p></li>
<li><p>Cleaned all syntax based on the <code>lintr</code> package</p></li>
<p>The default colours for labels and points is set with <code>scale_colour_viridis_d()</code>, but these can be changed by adding another scale for colour, like <code>scale_colour_brewer()</code>.</p>
The <ahref='lifecycle.html'>lifecycle</a> of this function is <strong>maturing</strong>. The unlying code of a maturing function has been roughed out, but finer details might still change. We will strive to maintain backward compatibility, but the function needs wider usage and more extensive testing in order to optimise the unlying code.</p>
<p>Developed by <ahref='https://www.rug.nl/staff/m.s.berends/'>Matthijs S. Berends</a>, <ahref='https://www.rug.nl/staff/c.f.luz/'>Christian F. Luz</a>, <ahref='https://www.rug.nl/staff/a.w.friedrich/'>Alexander W. Friedrich</a>, <ahref='https://www.rug.nl/staff/b.sinha/'>Bhanu N. M. Sinha</a>, <ahref='https://www.rug.nl/staff/c.j.albers/'>Casper J. Albers</a>, <ahref='https://www.rug.nl/staff/c.glasner/'>Corinna Glasner</a>.</p>
</div>
<divclass="pkgdown">
<p>Site built with <ahref="https://pkgdown.r-lib.org/">pkgdown</a> 1.4.1.</p>