<!-- Generated by pkgdown: do not edit by hand --><htmllang="en"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no"><metaname="description"content="Use these functions to create bar plots for AMR data analysis. All functions rely on ggplot2 functions."><title>AMR Plots with ggplot2 — ggplot_rsi • AMR (for R)</title><!-- favicons --><linkrel="icon"type="image/png"sizes="16x16"href="../favicon-16x16.png"><linkrel="icon"type="image/png"sizes="32x32"href="../favicon-32x32.png"><linkrel="apple-touch-icon"type="image/png"sizes="180x180"href="../apple-touch-icon.png"><linkrel="apple-touch-icon"type="image/png"sizes="120x120"href="../apple-touch-icon-120x120.png"><linkrel="apple-touch-icon"type="image/png"sizes="76x76"href="../apple-touch-icon-76x76.png"><linkrel="apple-touch-icon"type="image/png"sizes="60x60"href="../apple-touch-icon-60x60.png"><scriptsrc="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no"><linkhref="../deps/bootstrap-5.1.3/bootstrap.min.css"rel="stylesheet"><scriptsrc="../deps/bootstrap-5.1.3/bootstrap.bundle.min.js"></script><linkhref="../deps/Fira_Code-0.4.4/font.css"rel="stylesheet"><!-- Font Awesome icons --><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css"integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk="crossorigin="anonymous"><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css"integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw="crossorigin="anonymous"><!-- bootstrap-toc --><scriptsrc="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.js"></script><!-- headroom.js --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js"integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js"integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4="crossorigin="anonymous"></script><!-- clipboard.js --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js"integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI="crossorigin="anonymous"></script><!-- search --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js"integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A=="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js"integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg=="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js"integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww=="crossorigin="anonymous"></script><!-- pkgdown --><scriptsrc="../pkgdown.js"></script><linkhref="../extra.css"rel="stylesheet"><scriptsrc="../extra.js"></script><metaproperty="og:title"content="AMR Plots with ggplot2 — ggplot_rsi"><metaproperty="og:description"content="Use these functions to create bar plots for AMR data analysis. All functions rely on ggplot2 functions."><metaproperty="og:image"content="https://msberends.github.io/AMR/logo.svg"><metaname="twitter:card"content="summary_large_image"><metaname="twitter:creator"content="@msberends"><metaname="twitter:site"content="@msberends"><!-- mathjax --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js"integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/conf
<p>Use these functions to create bar plots for AMR data analysis. All functions rely on <ahref="https://ggplot2.tidyverse.org/reference/ggplot.html"class="external-link">ggplot2</a> functions.</p>
<span> language <spanclass="op">=</span><spanclass="fu"><ahref="translate.html">get_AMR_locale</a></span><spanclass="op">(</span><spanclass="op">)</span>,</span>
<span> colours <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span>S <spanclass="op">=</span><spanclass="st">"#3CAEA3"</span>, SI <spanclass="op">=</span><spanclass="st">"#3CAEA3"</span>, I <spanclass="op">=</span><spanclass="st">"#F6D55C"</span>, IR <spanclass="op">=</span><spanclass="st">"#ED553B"</span>, R <spanclass="op">=</span></span>
<span> position <spanclass="op">=</span><spanclass="cn">NULL</span>,</span>
<span> x <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="st">"antibiotic"</span>, <spanclass="st">"interpretation"</span><spanclass="op">)</span>,</span>
<span> fill <spanclass="op">=</span><spanclass="st">"interpretation"</span>,</span>
<span> language <spanclass="op">=</span><spanclass="fu"><ahref="translate.html">get_AMR_locale</a></span><spanclass="op">(</span><spanclass="op">)</span>,</span>
<span> language <spanclass="op">=</span><spanclass="fu"><ahref="translate.html">get_AMR_locale</a></span><spanclass="op">(</span><spanclass="op">)</span>,</span>
<dd><p>a <ahref="https://rdrr.io/r/base/data.frame.html"class="external-link">data.frame</a> with column(s) of class <code><ahref="as.rsi.html">rsi</a></code> (see <code><ahref="as.rsi.html">as.rsi()</a></code>)</p></dd>
<dt>position</dt>
<dd><p>position adjustment of bars, either <code>"fill"</code>, <code>"stack"</code> or <code>"dodge"</code></p></dd>
<dt>x</dt>
<dd><p>variable to show on x axis, either <code>"antibiotic"</code> (default) or <code>"interpretation"</code> or a grouping variable</p></dd>
<dt>fill</dt>
<dd><p>variable to categorise using the plots legend, either <code>"antibiotic"</code> (default) or <code>"interpretation"</code> or a grouping variable</p></dd>
<dt>facet</dt>
<dd><p>variable to split plots by, either <code>"interpretation"</code> (default) or <code>"antibiotic"</code> or a grouping variable</p></dd>
<dt>breaks</dt>
<dd><p>a <ahref="https://rdrr.io/r/base/numeric.html"class="external-link">numeric</a> vector of positions</p></dd>
<dt>limits</dt>
<dd><p>a <ahref="https://rdrr.io/r/base/numeric.html"class="external-link">numeric</a> vector of length two providing limits of the scale, use <code>NA</code> to refer to the existing minimum or maximum</p></dd>
<dt>translate_ab</dt>
<dd><p>a column name of the <ahref="antibiotics.html">antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><ahref="ab_property.html">ab_property()</a></code></p></dd>
<dd><p>a <ahref="https://rdrr.io/r/base/logical.html"class="external-link">logical</a> to indicate whether all values of S and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant), defaults to <code>TRUE</code></p></dd>
<dd><p>the minimum allowed number of available (tested) isolates. Any isolate count lower than <code>minimum</code> will return <code>NA</code> with a warning. The default number of <code>30</code> isolates is advised by the Clinical and Laboratory Standards Institute (CLSI) as best practice, see <em>Source</em>.</p></dd>
<dt>language</dt>
<dd><p>language of the returned text, defaults to system language (see <code><ahref="translate.html">get_AMR_locale()</a></code>) and can also be set with <code>getOption("AMR_locale")</code>. Use <code>language = NULL</code> or <code>language = ""</code> to prevent translation.</p></dd>
<dt>nrow</dt>
<dd><p>(when using <code>facet</code>) number of rows</p></dd>
<dt>colours</dt>
<dd><p>a named vactor with colour to be used for filling. The default colours are colour-blind friendly.</p></dd>
<dt>datalabels</dt>
<dd><p>show datalabels using <code>labels_rsi_count()</code></p></dd>
<dt>datalabels.size</dt>
<dd><p>size of the datalabels</p></dd>
<dt>datalabels.colour</dt>
<dd><p>colour of the datalabels</p></dd>
<dt>title</dt>
<dd><p>text to show as title of the plot</p></dd>
<dt>subtitle</dt>
<dd><p>text to show as subtitle of the plot</p></dd>
<dt>caption</dt>
<dd><p>text to show as caption of the plot</p></dd>
<dt>x.title</dt>
<dd><p>text to show as x axis description</p></dd>
<dt>y.title</dt>
<dd><p>text to show as y axis description</p></dd>
<dt>...</dt>
<dd><p>other arguments passed on to <code>geom_rsi()</code> or, in case of <code>scale_rsi_colours()</code>, named values to set colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. See <em>Examples</em>.</p></dd>
<dt>aesthetics</dt>
<dd><p>aesthetics to apply the colours to, defaults to "fill" but can also be (a combination of) "alpha", "colour", "fill", "linetype", "shape" or "size"</p></dd>
<p>At default, the names of antibiotics will be shown on the plots using <code><ahref="ab_property.html">ab_name()</a></code>. This can be set with the <code>translate_ab</code> argument. See <code><ahref="count.html">count_df()</a></code>.</p><divclass="section">
<p><code>geom_rsi()</code> will take any variable from the data that has an <code><ahref="as.rsi.html">rsi</a></code> class (created with <code><ahref="as.rsi.html">as.rsi()</a></code>) using <code><ahref="proportion.html">rsi_df()</a></code> and will plot bars with the percentage R, I and S. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis.</p>
<p><code>facet_rsi()</code> creates 2d plots (at default based on S/I/R) using <code><ahref="https://ggplot2.tidyverse.org/reference/facet_wrap.html"class="external-link">ggplot2::facet_wrap()</a></code>.</p>
<p><code>scale_y_percent()</code> transforms the y axis to a 0 to 100% range using <code><ahref="https://ggplot2.tidyverse.org/reference/scale_continuous.html"class="external-link">ggplot2::scale_y_continuous()</a></code>.</p>
<p><code>scale_rsi_colours()</code> sets colours to the bars (green for S, yellow for I, and red for R). with multilingual support. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red.</p>
<p><code>theme_rsi()</code> is a [ggplot2 theme][<code><ahref="https://ggplot2.tidyverse.org/reference/theme.html"class="external-link">ggplot2::theme()</a></code> with minimal distraction.</p>
<p><code>labels_rsi_count()</code> print datalabels on the bars with percentage and amount of isolates using <code><ahref="https://ggplot2.tidyverse.org/reference/geom_text.html"class="external-link">ggplot2::geom_text()</a></code>.</p>
<p><code>ggplot_rsi()</code> is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (<code>%>%</code>). See <em>Examples</em>.</p>
<spanclass="r-in"><span> x <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="st">"Value1"</span>, <spanclass="st">"Value2"</span>, <spanclass="st">"Value3"</span><spanclass="op">)</span>,</span></span>
<spanclass="r-in"><span> y <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="fl">1</span>, <spanclass="fl">2</span>, <spanclass="fl">3</span><spanclass="op">)</span>,</span></span>
<spanclass="r-in"><span> z <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="st">"Value4"</span>, <spanclass="st">"Value5"</span>, <spanclass="st">"Value6"</span><spanclass="op">)</span></span></span>
<spanclass="r-in"><span><spanclass="fu"><ahref="https://ggplot2.tidyverse.org/reference/geom_bar.html"class="external-link">geom_col</a></span><spanclass="op">(</span><spanclass="fu"><ahref="https://ggplot2.tidyverse.org/reference/aes.html"class="external-link">aes</a></span><spanclass="op">(</span>x <spanclass="op">=</span><spanclass="va">x</span>, y <spanclass="op">=</span><spanclass="va">y</span>, fill <spanclass="op">=</span><spanclass="va">z</span><spanclass="op">)</span><spanclass="op">)</span><spanclass="op">+</span></span></span>
<p></p><p><code>AMR</code> (for R). Free and open-source, licenced under the <atarget="_blank"href="https://github.com/msberends/AMR/blob/main/LICENSE"class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <atarget="_blank"href="https://www.rug.nl"class="external-link">University of Groningen</a> and <atarget="_blank"href="https://www.umcg.nl"class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>