AMR/docs/reference/ggplot_rsi.html

414 lines
35 KiB
HTML
Raw Normal View History

2018-12-23 21:26:21 +01:00
<!DOCTYPE html>
2021-12-12 11:07:02 +01:00
<!-- 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>AMR Plots with ggplot2 — ggplot_rsi • AMR (for R)</title><!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png"><link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png"><link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png"><link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png"><link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png"><!-- 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><link href="../extra.css" rel="stylesheet"><script src="../extra.js"></script><meta property="og:title" content="AMR Plots with ggplot2 — ggplot_rsi"><meta property="og:description" content="Use these functions to create bar plots for AMR data analysis. All functions rely on ggplot2 functions."><meta property="og:image" content="https://msberends.github.io/AMR/logo.svg"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:creator" content="@msberends"><meta name="twitter:site" content="@univgroningen"><!-- 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]>
2018-12-23 21:26:21 +01:00
<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">
2018-12-23 21:26:21 +01:00
<div class="container template-reference-topic">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
2018-12-23 21:26:21 +01:00
<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">
2018-12-29 22:24:19 +01:00
<a class="navbar-link" href="../index.html">AMR (for R)</a>
2022-05-11 10:10:31 +02:00
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.8.1.9007</span>
2018-12-23 21:26:21 +01:00
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav"><li>
2018-12-23 21:26:21 +01:00
<a href="../index.html">
<span class="fa fa-home"></span>
2018-12-23 21:26:21 +01:00
2018-12-29 22:24:19 +01:00
Home
2018-12-23 21:26:21 +01:00
</a>
</li>
2019-01-02 23:24:07 +01:00
<li class="dropdown">
2022-05-11 10:10:31 +02:00
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="fa fa-question-circle"></span>
2019-01-02 23:24:07 +01:00
How to
2018-12-29 22:24:19 +01:00
2019-01-02 23:24:07 +01:00
<span class="caret"></span>
2018-12-29 22:24:19 +01:00
</a>
<ul class="dropdown-menu" role="menu"><li>
2019-01-02 23:24:07 +01:00
<a href="../articles/AMR.html">
<span class="fa fa-directions"></span>
2019-01-02 23:24:07 +01:00
Conduct AMR analysis
</a>
</li>
<li>
2019-02-14 10:23:51 +01:00
<a href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
2019-01-02 23:24:07 +01:00
Predict antimicrobial resistance
</a>
</li>
2020-08-21 11:40:13 +02:00
<li>
<a href="../articles/datasets.html">
<span class="fa fa-database"></span>
2020-08-21 11:40:13 +02:00
Data sets for download / own use
2020-08-21 11:40:13 +02:00
</a>
</li>
2020-04-13 21:09:56 +02:00
<li>
<a href="../articles/PCA.html">
<span class="fa fa-compress"></span>
2020-04-13 21:09:56 +02:00
Conduct principal component analysis for AMR
</a>
</li>
2019-05-23 16:58:59 +02:00
<li>
<a href="../articles/MDR.html">
<span class="fa fa-skull-crossbones"></span>
2019-05-23 16:58:59 +02:00
Determine multi-drug resistance (MDR)
</a>
</li>
2019-01-29 00:06:50 +01:00
<li>
<a href="../articles/WHONET.html">
<span class="fa fa-globe-americas"></span>
2019-01-29 00:06:50 +01:00
Work with WHONET data
</a>
</li>
2019-02-14 15:18:17 +01:00
<li>
<a href="../articles/SPSS.html">
<span class="fa fa-file-upload"></span>
2019-02-14 15:18:17 +01:00
Import data from SPSS/SAS/Stata
</a>
</li>
2019-01-02 23:24:07 +01:00
<li>
<a href="../articles/EUCAST.html">
<span class="fa fa-exchange-alt"></span>
2019-01-02 23:24:07 +01:00
Apply EUCAST rules
</a>
</li>
<li>
2019-02-14 10:23:51 +01:00
<a href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
2019-01-02 23:24:07 +01:00
Get properties of a microorganism
</a>
</li>
<li>
2019-05-10 16:44:59 +02:00
<a href="../reference/ab_property.html">
<span class="fa fa-capsules"></span>
2019-01-02 23:24:07 +01:00
Get properties of an antibiotic
</a>
</li>
2019-01-11 20:37:23 +01:00
<li>
<a href="../articles/benchmarks.html">
<span class="fa fa-shipping-fast"></span>
2019-01-11 20:37:23 +01:00
Other: benchmarks
</a>
</li>
</ul></li>
2018-12-23 21:26:21 +01:00
<li>
2020-07-28 18:39:57 +02:00
<a href="../reference/index.html">
<span class="fa fa-book-open"></span>
2018-12-29 22:24:19 +01:00
Manual
</a>
2018-12-23 21:26:21 +01:00
</li>
2018-12-29 22:24:19 +01:00
<li>
<a href="../authors.html">
<span class="fa fa-users"></span>
2018-12-23 21:26:21 +01:00
2018-12-29 22:24:19 +01:00
Authors
2018-12-23 21:26:21 +01:00
</a>
</li>
<li>
2020-07-28 18:39:57 +02:00
<a href="../news/index.html">
2021-05-12 18:15:03 +02:00
<span class="far fa-newspaper"></span>
2018-12-29 22:24:19 +01:00
Changelog
</a>
</li>
</ul><ul class="nav navbar-nav navbar-right"><li>
<a href="https://github.com/msberends/AMR" class="external-link">
2021-05-12 18:15:03 +02:00
<span class="fab fa-github"></span>
2018-12-29 22:24:19 +01:00
Source Code
</a>
</li>
</ul></div><!--/.nav-collapse -->
2018-12-23 21:26:21 +01:00
</div><!--/.container -->
</div><!--/.navbar -->
2019-10-13 09:31:58 +02:00
</header><div class="row">
2018-12-23 21:26:21 +01:00
<div class="col-md-9 contents">
<div class="page-header">
<h1>AMR Plots with <code>ggplot2</code></h1>
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/R/ggplot_rsi.R" class="external-link"><code>R/ggplot_rsi.R</code></a></small>
2018-12-23 21:26:21 +01:00
<div class="hidden name"><code>ggplot_rsi.Rd</code></div>
</div>
<div class="ref-description">
<p>Use these functions to create bar plots for AMR data analysis. All functions rely on <a href="https://ggplot2.tidyverse.org/reference/ggplot.html" class="external-link">ggplot2</a> functions.</p>
2018-12-23 21:26:21 +01:00
</div>
<div id="ref-usage">
<div class="sourceCode"><pre class="sourceCode r"><code><span class="fu">ggplot_rsi</span><span class="op">(</span>
<span class="va">data</span>,
position <span class="op">=</span> <span class="cn">NULL</span>,
x <span class="op">=</span> <span class="st">"antibiotic"</span>,
fill <span class="op">=</span> <span class="st">"interpretation"</span>,
facet <span class="op">=</span> <span class="cn">NULL</span>,
breaks <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq</a></span><span class="op">(</span><span class="fl">0</span>, <span class="fl">1</span>, <span class="fl">0.1</span><span class="op">)</span>,
limits <span class="op">=</span> <span class="cn">NULL</span>,
translate_ab <span class="op">=</span> <span class="st">"name"</span>,
combine_SI <span class="op">=</span> <span class="cn">TRUE</span>,
combine_IR <span class="op">=</span> <span class="cn">FALSE</span>,
minimum <span class="op">=</span> <span class="fl">30</span>,
language <span class="op">=</span> <span class="fu"><a href="translate.html">get_AMR_locale</a></span><span class="op">(</span><span class="op">)</span>,
nrow <span class="op">=</span> <span class="cn">NULL</span>,
colours <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>S <span class="op">=</span> <span class="st">"#3CAEA3"</span>, SI <span class="op">=</span> <span class="st">"#3CAEA3"</span>, I <span class="op">=</span> <span class="st">"#F6D55C"</span>, IR <span class="op">=</span> <span class="st">"#ED553B"</span>, R <span class="op">=</span>
<span class="st">"#ED553B"</span><span class="op">)</span>,
datalabels <span class="op">=</span> <span class="cn">TRUE</span>,
datalabels.size <span class="op">=</span> <span class="fl">2.5</span>,
datalabels.colour <span class="op">=</span> <span class="st">"grey15"</span>,
title <span class="op">=</span> <span class="cn">NULL</span>,
subtitle <span class="op">=</span> <span class="cn">NULL</span>,
caption <span class="op">=</span> <span class="cn">NULL</span>,
x.title <span class="op">=</span> <span class="st">"Antimicrobial"</span>,
y.title <span class="op">=</span> <span class="st">"Proportion"</span>,
<span class="va">...</span>
<span class="op">)</span>
<span class="fu">geom_rsi</span><span class="op">(</span>
position <span class="op">=</span> <span class="cn">NULL</span>,
x <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">"antibiotic"</span>, <span class="st">"interpretation"</span><span class="op">)</span>,
fill <span class="op">=</span> <span class="st">"interpretation"</span>,
translate_ab <span class="op">=</span> <span class="st">"name"</span>,
minimum <span class="op">=</span> <span class="fl">30</span>,
language <span class="op">=</span> <span class="fu"><a href="translate.html">get_AMR_locale</a></span><span class="op">(</span><span class="op">)</span>,
combine_SI <span class="op">=</span> <span class="cn">TRUE</span>,
combine_IR <span class="op">=</span> <span class="cn">FALSE</span>,
<span class="va">...</span>
<span class="op">)</span>
<span class="fu">facet_rsi</span><span class="op">(</span>facet <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">"interpretation"</span>, <span class="st">"antibiotic"</span><span class="op">)</span>, nrow <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span>
<span class="fu">scale_y_percent</span><span class="op">(</span>breaks <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/seq.html" class="external-link">seq</a></span><span class="op">(</span><span class="fl">0</span>, <span class="fl">1</span>, <span class="fl">0.1</span><span class="op">)</span>, limits <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span>
<span class="fu">scale_rsi_colours</span><span class="op">(</span><span class="va">...</span>, aesthetics <span class="op">=</span> <span class="st">"fill"</span><span class="op">)</span>
<span class="fu">theme_rsi</span><span class="op">(</span><span class="op">)</span>
<span class="fu">labels_rsi_count</span><span class="op">(</span>
position <span class="op">=</span> <span class="cn">NULL</span>,
x <span class="op">=</span> <span class="st">"antibiotic"</span>,
translate_ab <span class="op">=</span> <span class="st">"name"</span>,
minimum <span class="op">=</span> <span class="fl">30</span>,
language <span class="op">=</span> <span class="fu"><a href="translate.html">get_AMR_locale</a></span><span class="op">(</span><span class="op">)</span>,
combine_SI <span class="op">=</span> <span class="cn">TRUE</span>,
combine_IR <span class="op">=</span> <span class="cn">FALSE</span>,
datalabels.size <span class="op">=</span> <span class="fl">3</span>,
datalabels.colour <span class="op">=</span> <span class="st">"grey15"</span>
<span class="op">)</span></code></pre></div>
</div>
<div id="arguments">
<h2>Arguments</h2>
<dl><dt>data</dt>
<dd><p>a <a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a> with column(s) of class <code><a href="as.rsi.html">rsi</a></code> (see <code><a href="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 <a href="https://rdrr.io/r/base/numeric.html" class="external-link">numeric</a> vector of positions</p></dd>
<dt>limits</dt>
<dd><p>a <a href="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 <a href="antibiotics.html">antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><a href="ab_property.html">ab_property()</a></code></p></dd>
<dt>combine_SI</dt>
<dd><p>a <a href="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 <a href="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><a href="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>
</dl></div>
<div id="details">
<h2>Details</h2>
<p>At default, the names of antibiotics will be shown on the plots using <code><a href="ab_property.html">ab_name()</a></code>. This can be set with the <code>translate_ab</code> argument. See <code><a href="count.html">count_df()</a></code>.</p><div class="section">
<h3 id="the-functions">The Functions<a class="anchor" aria-label="anchor" href="#the-functions"></a></h3>
<p><code>geom_rsi()</code> will take any variable from the data that has an <code><a href="as.rsi.html">rsi</a></code> class (created with <code><a href="as.rsi.html">as.rsi()</a></code>) using <code><a href="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><a href="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><a href="https://ggplot2.tidyverse.org/reference/scale_continuous.html" class="external-link">ggplot2::scale_y_continuous()</a></code>.</p>
2021-02-26 12:11:29 +01:00
<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><a href="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><a href="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>%&gt;%</code>). See <em>Examples</em>.</p>
</div>
</div>
<div id="stable-lifecycle">
<h2>Stable Lifecycle</h2>
<p><img src="figures/lifecycle_stable.svg" style='margin-bottom:"5"'><br>
The <a href="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>
2022-03-10 19:33:25 +01:00
<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 a 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>
</div>
<div id="read-more-on-our-website-">
<h2>Read more on Our Website!</h2>
2019-01-02 23:24:07 +01:00
2019-10-13 09:31:58 +02:00
<p>On our website <a href="https://msberends.github.io/AMR/">https://msberends.github.io/AMR/</a> you can find <a href="https://msberends.github.io/AMR/articles/AMR.html">a comprehensive tutorial</a> about how to conduct AMR data analysis, the <a href="https://msberends.github.io/AMR/reference/">complete documentation of all functions</a> and <a href="https://msberends.github.io/AMR/articles/WHONET.html">an example analysis using WHONET data</a>.</p>
</div>
2018-12-23 21:26:21 +01:00
<div id="ref-examples">
<h2>Examples</h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span class="co"># \donttest{</span>
<span class="kw">if</span> <span class="op">(</span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">require</a></span><span class="op">(</span><span class="st"><a href="https://ggplot2.tidyverse.org" class="external-link">"ggplot2"</a></span><span class="op">)</span> <span class="op">&amp;</span> <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">require</a></span><span class="op">(</span><span class="st"><a href="https://dplyr.tidyverse.org" class="external-link">"dplyr"</a></span><span class="op">)</span><span class="op">)</span> <span class="op">{</span>
2020-08-10 12:46:03 +02:00
<span class="co"># get antimicrobial results for drugs against a UTI:</span>
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html" class="external-link">ggplot</a></span><span class="op">(</span><span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">AMX</span>, <span class="va">NIT</span>, <span class="va">FOS</span>, <span class="va">TMP</span>, <span class="va">CIP</span><span class="op">)</span><span class="op">)</span> <span class="op">+</span>
<span class="fu">geom_rsi</span><span class="op">(</span><span class="op">)</span>
2020-08-10 12:46:03 +02:00
<span class="co"># prettify the plot using some additional functions:</span>
<span class="va">df</span> <span class="op">&lt;-</span> <span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">AMX</span>, <span class="va">NIT</span>, <span class="va">FOS</span>, <span class="va">TMP</span>, <span class="va">CIP</span><span class="op">)</span>
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html" class="external-link">ggplot</a></span><span class="op">(</span><span class="va">df</span><span class="op">)</span> <span class="op">+</span>
<span class="fu">geom_rsi</span><span class="op">(</span><span class="op">)</span> <span class="op">+</span>
<span class="fu">scale_y_percent</span><span class="op">(</span><span class="op">)</span> <span class="op">+</span>
<span class="fu">scale_rsi_colours</span><span class="op">(</span><span class="op">)</span> <span class="op">+</span>
<span class="fu">labels_rsi_count</span><span class="op">(</span><span class="op">)</span> <span class="op">+</span>
<span class="fu">theme_rsi</span><span class="op">(</span><span class="op">)</span>
2020-08-10 12:46:03 +02:00
<span class="co"># or better yet, simplify this using the wrapper function - a single command:</span>
<span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">AMX</span>, <span class="va">NIT</span>, <span class="va">FOS</span>, <span class="va">TMP</span>, <span class="va">CIP</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu">ggplot_rsi</span><span class="op">(</span><span class="op">)</span>
2020-08-10 12:46:03 +02:00
<span class="co"># get only proportions and no counts:</span>
<span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">AMX</span>, <span class="va">NIT</span>, <span class="va">FOS</span>, <span class="va">TMP</span>, <span class="va">CIP</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu">ggplot_rsi</span><span class="op">(</span>datalabels <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span>
2020-08-10 12:46:03 +02:00
<span class="co"># add other ggplot2 arguments as you like:</span>
<span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">AMX</span>, <span class="va">NIT</span>, <span class="va">FOS</span>, <span class="va">TMP</span>, <span class="va">CIP</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu">ggplot_rsi</span><span class="op">(</span>width <span class="op">=</span> <span class="fl">0.5</span>,
colour <span class="op">=</span> <span class="st">"black"</span>,
size <span class="op">=</span> <span class="fl">1</span>,
linetype <span class="op">=</span> <span class="fl">2</span>,
alpha <span class="op">=</span> <span class="fl">0.25</span><span class="op">)</span>
<span class="co"># you can alter the colours with colour names:</span>
<span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">AMX</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu">ggplot_rsi</span><span class="op">(</span>colours <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>SI <span class="op">=</span> <span class="st">"yellow"</span><span class="op">)</span><span class="op">)</span>
<span class="co"># but you can also use the built-in colour-blind friendly colours for</span>
<span class="co"># your plots, where "S" is green, "I" is yellow and "R" is red:</span>
<span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>x <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">"Value1"</span>, <span class="st">"Value2"</span>, <span class="st">"Value3"</span><span class="op">)</span>,
y <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="fl">1</span>, <span class="fl">2</span>, <span class="fl">3</span><span class="op">)</span>,
z <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">"Value4"</span>, <span class="st">"Value5"</span>, <span class="st">"Value6"</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 class="fu"><a href="https://ggplot2.tidyverse.org/reference/ggplot.html" class="external-link">ggplot</a></span><span class="op">(</span><span class="op">)</span> <span class="op">+</span>
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/geom_bar.html" class="external-link">geom_col</a></span><span class="op">(</span><span class="fu"><a href="https://ggplot2.tidyverse.org/reference/aes.html" class="external-link">aes</a></span><span class="op">(</span>x <span class="op">=</span> <span class="va">x</span>, y <span class="op">=</span> <span class="va">y</span>, fill <span class="op">=</span> <span class="va">z</span><span class="op">)</span><span class="op">)</span> <span class="op">+</span>
<span class="fu">scale_rsi_colours</span><span class="op">(</span>Value4 <span class="op">=</span> <span class="st">"S"</span>, Value5 <span class="op">=</span> <span class="st">"I"</span>, Value6 <span class="op">=</span> <span class="st">"R"</span><span class="op">)</span>
2020-08-10 12:46:03 +02:00
<span class="co"># resistance of ciprofloxacine per age group</span>
<span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/mutate.html" class="external-link">mutate</a></span><span class="op">(</span>first_isolate <span class="op">=</span> <span class="fu"><a href="first_isolate.html">first_isolate</a></span><span class="op">(</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 class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html" class="external-link">filter</a></span><span class="op">(</span><span class="va">first_isolate</span> <span class="op">==</span> <span class="cn">TRUE</span>,
<span class="va">mo</span> <span class="op">==</span> <span class="fu"><a href="as.mo.html">as.mo</a></span><span class="op">(</span><span class="st">"E. coli"</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 class="co"># age_groups() is also a function in this AMR package:</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span>age_group <span class="op">=</span> <span class="fu"><a href="age_groups.html">age_groups</a></span><span class="op">(</span><span class="va">age</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 class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">age_group</span>, <span class="va">CIP</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu">ggplot_rsi</span><span class="op">(</span>x <span class="op">=</span> <span class="st">"age_group"</span><span class="op">)</span>
2020-08-10 12:46:03 +02:00
<span class="co"># a shorter version which also adjusts data label colours:</span>
<span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">AMX</span>, <span class="va">NIT</span>, <span class="va">FOS</span>, <span class="va">TMP</span>, <span class="va">CIP</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu">ggplot_rsi</span><span class="op">(</span>colours <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span>
<span class="co"># it also supports groups (don't forget to use the group var on `x` or `facet`):</span>
<span class="va">example_isolates</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></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="fu"><a href="mo_property.html">mo_is_gram_negative</a></span><span class="op">(</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 class="co"># select only UTI-specific drugs</span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/select.html" class="external-link">select</a></span><span class="op">(</span><span class="va">hospital_id</span>, <span class="va">AMX</span>, <span class="va">NIT</span>, <span class="va">FOS</span>, <span class="va">TMP</span>, <span class="va">CIP</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu"><a href="https://dplyr.tidyverse.org/reference/group_by.html" class="external-link">group_by</a></span><span class="op">(</span><span class="va">hospital_id</span><span class="op">)</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html" class="external-link">%&gt;%</a></span>
<span class="fu">ggplot_rsi</span><span class="op">(</span>x <span class="op">=</span> <span class="st">"hospital_id"</span>,
facet <span class="op">=</span> <span class="st">"antibiotic"</span>,
nrow <span class="op">=</span> <span class="fl">1</span>,
title <span class="op">=</span> <span class="st">"AMR of Anti-UTI Drugs Per Hospital"</span>,
x.title <span class="op">=</span> <span class="st">"Hospital"</span>,
datalabels <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span>
<span class="op">}</span>
<span class="co"># }</span>
</code></pre></div>
</div>
2018-12-23 21:26:21 +01:00
</div>
2020-04-13 21:09:56 +02:00
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<nav id="toc" data-toggle="toc" class="sticky-top"><h2 data-toc-skip>Contents</h2>
</nav></div>
2018-12-23 21:26:21 +01:00
</div>
2019-10-13 09:31:58 +02:00
<footer><div class="copyright">
2022-03-27 09:37:55 +02:00
<p></p><p>Developed by Matthijs S. Berends, Christian F. Luz, Dennis Souverein, Erwin E. A. Hassing.</p>
2018-12-23 21:26:21 +01:00
</div>
<div class="pkgdown">
2022-05-11 10:10:31 +02:00
<p></p><p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.0.3.</p>
2018-12-23 21:26:21 +01:00
</div>
2019-10-13 09:31:58 +02:00
</footer></div>
2018-12-23 21:26:21 +01:00
2019-10-13 09:31:58 +02:00
</body></html>
2019-10-13 09:31:58 +02:00