<!-- 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.0"><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"><!-- jquery --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="crossorigin="anonymous"></script><!-- Bootstrap --><linkhref="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.4.0/flatly/bootstrap.min.css"rel="stylesheet"crossorigin="anonymous"><scriptsrc="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 --><linkrel="stylesheet"href="../bootstrap-toc.css"><scriptsrc="../bootstrap-toc.js"></script><!-- 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"><!-- 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><!-- 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><!-- pkgdown --><linkhref="../pkgdown.css"rel="stylesheet"><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.png"><metaname="twitter:card"content="summary_large_image"><metaname="twitter:creator"content="@msberends"><metaname="twitter:site"content="@univgroningen"><!-- 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/config/TeX-AMS-MML_HTMLorMML.js"integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA="crossorigin="anonymous"></script><!--[if lt IE 9]>
<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>
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>
position <spanclass="op">=</span><spanclass="cn">NULL</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>,
fill <spanclass="op">=</span><spanclass="st">"interpretation"</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>
<dt>combine_SI</dt>
<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). This used to be the argument <code>combine_IR</code>, but this now follows the redefinition by EUCAST about the interpretation of I (increased exposure) in 2019, see section 'Interpretation of S, I and R' below. Default is <code>TRUE</code>.</p></dd>
<dt>combine_IR</dt>
<dd><p>a <ahref="https://rdrr.io/r/base/logical.html"class="external-link">logical</a> to indicate whether all values of I and R must be merged into one, so the output only consists of S vs. I+R (susceptible vs. non-susceptible). This is outdated, see argument <code>combine_SI</code>.</p></dd>
<dt>minimum</dt>
<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_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>
</dl></div>
<divid="details">
<h2>Details</h2>
<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>
The <ahref="lifecycle.html">lifecycle</a> of this function is <strong>stable</strong>. In a stable function, major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; removing arguments or changing the meaning of existing arguments will be avoided.</p>
<p>If the unlying code needs breaking changes, they will occur gradually. For example, an argument will be deprecated and first continue to work, but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.</p>
<p>On our website <ahref="https://msberends.github.io/AMR/">https://msberends.github.io/AMR/</a> you can find <ahref="https://msberends.github.io/AMR/articles/AMR.html">a comprehensive tutorial</a> about how to conduct AMR data analysis, the <ahref="https://msberends.github.io/AMR/reference/">complete documentation of all functions</a> and <ahref="https://msberends.github.io/AMR/articles/WHONET.html">an example analysis using WHONET data</a>.</p>
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>,
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><spanclass="op">)</span><spanclass="op"><ahref="https://magrittr.tidyverse.org/reference/pipe.html"class="external-link">%>%</a></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>