1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 18:46:13 +01:00
AMR/reference/ggplot_sir.html

362 lines
47 KiB
HTML
Raw Normal View History

2022-08-21 16:59:35 +02:00
<!DOCTYPE html>
2024-11-21 10:17:08 +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, shrink-to-fit=no"><title>AMR Plots with ggplot2 — ggplot_sir • 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"><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/Lato-0.4.9/font.css" rel="stylesheet"><link href="../deps/Fira_Code-0.4.9/font.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><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_sir"><meta name="description" content="Use these functions to create bar plots for AMR data analysis. All functions rely on ggplot2 functions."><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"></head><body>
2022-08-21 16:59:35 +02:00
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
2024-07-16 15:00:55 +02:00
<nav class="navbar navbar-expand-lg fixed-top bg-primary" data-bs-theme="dark" aria-label="Site navigation"><div class="container">
2022-08-21 16:59:35 +02:00
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
2024-12-13 09:54:23 +01:00
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">2.1.1.9116</small>
2024-07-16 15:00:55 +02:00
2022-08-21 16:59:35 +02:00
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar" class="collapse navbar-collapse ms-3">
2023-05-24 16:03:18 +02:00
<ul class="navbar-nav me-auto"><li class="nav-item dropdown">
2024-07-16 15:00:55 +02:00
<button class="nav-link dropdown-toggle" type="button" id="dropdown-how-to" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true"><span class="fa fa-question-circle"></span> How to</button>
<ul class="dropdown-menu" aria-labelledby="dropdown-how-to"><li><a class="dropdown-item" href="../articles/AMR.html"><span class="fa fa-directions"></span> Conduct AMR Analysis</a></li>
<li><a class="dropdown-item" href="../reference/antibiogram.html"><span class="fa fa-file-prescription"></span> Generate Antibiogram (Trad./Syndromic/WISCA)</a></li>
<li><a class="dropdown-item" href="../articles/resistance_predict.html"><span class="fa fa-dice"></span> Predict Antimicrobial Resistance</a></li>
<li><a class="dropdown-item" href="../articles/datasets.html"><span class="fa fa-database"></span> Download Data Sets for Own Use</a></li>
<li><a class="dropdown-item" href="../reference/AMR-options.html"><span class="fa fa-gear"></span> Set User- Or Team-specific Package Settings</a></li>
<li><a class="dropdown-item" href="../articles/PCA.html"><span class="fa fa-compress"></span> Conduct Principal Component Analysis for AMR</a></li>
<li><a class="dropdown-item" href="../articles/MDR.html"><span class="fa fa-skull-crossbones"></span> Determine Multi-Drug Resistance (MDR)</a></li>
<li><a class="dropdown-item" href="../articles/WHONET.html"><span class="fa fa-globe-americas"></span> Work with WHONET Data</a></li>
<li><a class="dropdown-item" href="../articles/EUCAST.html"><span class="fa fa-exchange-alt"></span> Apply Eucast Rules</a></li>
<li><a class="dropdown-item" href="../reference/mo_property.html"><span class="fa fa-bug"></span> Get Taxonomy of a Microorganism</a></li>
<li><a class="dropdown-item" href="../reference/ab_property.html"><span class="fa fa-capsules"></span> Get Properties of an Antibiotic Drug</a></li>
<li><a class="dropdown-item" href="../reference/av_property.html"><span class="fa fa-capsules"></span> Get Properties of an Antiviral Drug</a></li>
</ul></li>
2024-09-30 22:12:21 +02:00
<li class="nav-item"><a class="nav-link" href="../articles/AMR_for_Python.html"><span class="fa fab fa-python"></span> AMR for Python</a></li>
2024-07-16 15:00:55 +02:00
<li class="active nav-item"><a class="nav-link" href="../reference/index.html"><span class="fa fa-book-open"></span> Manual</a></li>
<li class="nav-item"><a class="nav-link" href="../authors.html"><span class="fa fa-users"></span> Authors</a></li>
</ul><ul class="navbar-nav"><li class="nav-item"><a class="nav-link" href="../news/index.html"><span class="fa far fa-newspaper"></span> Changelog</a></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/msberends/AMR"><span class="fa fab fa-github"></span> Source Code</a></li>
2022-08-21 16:59:35 +02:00
</ul></div>
2024-07-16 15:00:55 +02:00
2022-08-21 16:59:35 +02:00
</div>
</nav><div class="container template-reference-topic">
<div class="row">
<main id="main" class="col-md-9"><div class="page-header">
<img src="../logo.svg" class="logo" alt=""><h1>AMR Plots with <code>ggplot2</code></h1>
2024-07-16 15:00:55 +02:00
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/main/R/ggplot_sir.R" class="external-link"><code>R/ggplot_sir.R</code></a></small>
2023-01-21 23:53:21 +01:00
<div class="d-none name"><code>ggplot_sir.Rd</code></div>
2022-08-21 16:59:35 +02:00
</div>
<div class="ref-description section level2">
<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>
</div>
<div class="section level2">
<h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
2023-01-21 23:53:21 +01:00
<div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">ggplot_sir</span><span class="op">(</span></span>
2022-08-21 16:59:35 +02:00
<span> <span class="va">data</span>,</span>
<span> position <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> x <span class="op">=</span> <span class="st">"antibiotic"</span>,</span>
<span> fill <span class="op">=</span> <span class="st">"interpretation"</span>,</span>
<span> facet <span class="op">=</span> <span class="cn">NULL</span>,</span>
<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>,</span>
<span> limits <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> translate_ab <span class="op">=</span> <span class="st">"name"</span>,</span>
<span> combine_SI <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> minimum <span class="op">=</span> <span class="fl">30</span>,</span>
<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>,</span>
<span> nrow <span class="op">=</span> <span class="cn">NULL</span>,</span>
<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>
<span> <span class="st">"#ED553B"</span><span class="op">)</span>,</span>
<span> datalabels <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> datalabels.size <span class="op">=</span> <span class="fl">2.5</span>,</span>
<span> datalabels.colour <span class="op">=</span> <span class="st">"grey15"</span>,</span>
<span> title <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> subtitle <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> caption <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> x.title <span class="op">=</span> <span class="st">"Antimicrobial"</span>,</span>
<span> y.title <span class="op">=</span> <span class="st">"Proportion"</span>,</span>
<span> <span class="va">...</span></span>
<span><span class="op">)</span></span>
<span></span>
2023-01-21 23:53:21 +01:00
<span><span class="fu">geom_sir</span><span class="op">(</span></span>
2022-08-21 16:59:35 +02:00
<span> position <span class="op">=</span> <span class="cn">NULL</span>,</span>
<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>,</span>
<span> fill <span class="op">=</span> <span class="st">"interpretation"</span>,</span>
<span> translate_ab <span class="op">=</span> <span class="st">"name"</span>,</span>
<span> minimum <span class="op">=</span> <span class="fl">30</span>,</span>
<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>,</span>
<span> combine_SI <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> <span class="va">...</span></span>
<span><span class="op">)</span></span>
<span></span>
2023-01-21 23:53:21 +01:00
<span><span class="fu">facet_sir</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>
2022-08-21 16:59:35 +02:00
<span></span>
2024-12-13 09:54:23 +01:00
<span><span class="fu">scale_y_percent</span><span class="op">(</span></span>
<span> breaks <span class="op">=</span> <span class="kw">function</span><span class="op">(</span><span class="va">x</span><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="fu"><a href="https://rdrr.io/r/base/Extremes.html" class="external-link">max</a></span><span class="op">(</span><span class="va">x</span>, na.rm <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span>, <span class="fl">0.1</span><span class="op">)</span>,</span>
<span> limits <span class="op">=</span> <span class="cn">NULL</span></span>
<span><span class="op">)</span></span>
2022-08-21 16:59:35 +02:00
<span></span>
2023-01-21 23:53:21 +01:00
<span><span class="fu">scale_sir_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>
2022-08-21 16:59:35 +02:00
<span></span>
2023-01-21 23:53:21 +01:00
<span><span class="fu">theme_sir</span><span class="op">(</span><span class="op">)</span></span>
2022-08-21 16:59:35 +02:00
<span></span>
2023-01-21 23:53:21 +01:00
<span><span class="fu">labels_sir_count</span><span class="op">(</span></span>
2022-08-21 16:59:35 +02:00
<span> position <span class="op">=</span> <span class="cn">NULL</span>,</span>
<span> x <span class="op">=</span> <span class="st">"antibiotic"</span>,</span>
<span> translate_ab <span class="op">=</span> <span class="st">"name"</span>,</span>
<span> minimum <span class="op">=</span> <span class="fl">30</span>,</span>
<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>,</span>
<span> combine_SI <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span> datalabels.size <span class="op">=</span> <span class="fl">3</span>,</span>
<span> datalabels.colour <span class="op">=</span> <span class="st">"grey15"</span></span>
<span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>
2024-07-16 15:00:55 +02:00
<dl><dt id="arg-data">data<a class="anchor" aria-label="anchor" href="#arg-data"></a></dt>
2023-01-21 23:53:21 +01:00
<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.sir.html">sir</a></code> (see <code><a href="as.sir.html">as.sir()</a></code>)</p></dd>
2022-08-21 16:59:35 +02:00
2024-07-16 15:00:55 +02:00
<dt id="arg-position">position<a class="anchor" aria-label="anchor" href="#arg-position"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>position adjustment of bars, either <code>"fill"</code>, <code>"stack"</code> or <code>"dodge"</code></p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-x">x<a class="anchor" aria-label="anchor" href="#arg-x"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>variable to show on x axis, either <code>"antibiotic"</code> (default) or <code>"interpretation"</code> or a grouping variable</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-fill">fill<a class="anchor" aria-label="anchor" href="#arg-fill"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>variable to categorise using the plots legend, either <code>"antibiotic"</code> (default) or <code>"interpretation"</code> or a grouping variable</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-facet">facet<a class="anchor" aria-label="anchor" href="#arg-facet"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>variable to split plots by, either <code>"interpretation"</code> (default) or <code>"antibiotic"</code> or a grouping variable</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-breaks">breaks<a class="anchor" aria-label="anchor" href="#arg-breaks"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>a <a href="https://rdrr.io/r/base/numeric.html" class="external-link">numeric</a> vector of positions</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-limits">limits<a class="anchor" aria-label="anchor" href="#arg-limits"></a></dt>
2022-08-21 16:59:35 +02:00
<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>
2024-07-16 15:00:55 +02:00
<dt id="arg-translate-ab">translate_ab<a class="anchor" aria-label="anchor" href="#arg-translate-ab"></a></dt>
2022-08-21 16:59:35 +02:00
<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>
2024-07-16 15:00:55 +02:00
<dt id="arg-combine-si">combine_SI<a class="anchor" aria-label="anchor" href="#arg-combine-si"></a></dt>
2024-09-29 22:25:53 +02:00
<dd><p>a <a href="https://rdrr.io/r/base/logical.html" class="external-link">logical</a> to indicate whether all values of S, SDD, and I must be merged into one, so the output only consists of S+SDD+I vs. R (susceptible vs. resistant) - the default is <code>TRUE</code></p></dd>
2022-08-21 16:59:35 +02:00
2024-07-16 15:00:55 +02:00
<dt id="arg-minimum">minimum<a class="anchor" aria-label="anchor" href="#arg-minimum"></a></dt>
2022-08-21 16:59:35 +02:00
<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>
2024-07-16 15:00:55 +02:00
<dt id="arg-language">language<a class="anchor" aria-label="anchor" href="#arg-language"></a></dt>
2024-09-24 22:49:01 +02:00
<dd><p>language of the returned text - the default is the current system language (see <code><a href="translate.html">get_AMR_locale()</a></code>) and can also be set with the package option <code><a href="AMR-options.html">AMR_locale</a></code>. Use <code>language = NULL</code> or <code>language = ""</code> to prevent translation.</p></dd>
2022-08-21 16:59:35 +02:00
2024-07-16 15:00:55 +02:00
<dt id="arg-nrow">nrow<a class="anchor" aria-label="anchor" href="#arg-nrow"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>(when using <code>facet</code>) number of rows</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-colours">colours<a class="anchor" aria-label="anchor" href="#arg-colours"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>a named vactor with colour to be used for filling. The default colours are colour-blind friendly.</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-datalabels">datalabels<a class="anchor" aria-label="anchor" href="#arg-datalabels"></a></dt>
2023-01-21 23:53:21 +01:00
<dd><p>show datalabels using <code>labels_sir_count()</code></p></dd>
2022-08-21 16:59:35 +02:00
2024-07-16 15:00:55 +02:00
<dt id="arg-datalabels-size">datalabels.size<a class="anchor" aria-label="anchor" href="#arg-datalabels-size"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>size of the datalabels</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-datalabels-colour">datalabels.colour<a class="anchor" aria-label="anchor" href="#arg-datalabels-colour"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>colour of the datalabels</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-title">title<a class="anchor" aria-label="anchor" href="#arg-title"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>text to show as title of the plot</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-subtitle">subtitle<a class="anchor" aria-label="anchor" href="#arg-subtitle"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>text to show as subtitle of the plot</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-caption">caption<a class="anchor" aria-label="anchor" href="#arg-caption"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>text to show as caption of the plot</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-x-title">x.title<a class="anchor" aria-label="anchor" href="#arg-x-title"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>text to show as x axis description</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg-y-title">y.title<a class="anchor" aria-label="anchor" href="#arg-y-title"></a></dt>
2022-08-21 16:59:35 +02:00
<dd><p>text to show as y axis description</p></dd>
2024-07-16 15:00:55 +02:00
<dt id="arg--">...<a class="anchor" aria-label="anchor" href="#arg--"></a></dt>
2023-01-21 23:53:21 +01:00
<dd><p>other arguments passed on to <code>geom_sir()</code> or, in case of <code>scale_sir_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>
2022-08-21 16:59:35 +02:00
2024-07-16 15:00:55 +02:00
<dt id="arg-aesthetics">aesthetics<a class="anchor" aria-label="anchor" href="#arg-aesthetics"></a></dt>
2023-02-22 14:47:35 +01:00
<dd><p>aesthetics to apply the colours to - the default is "fill" but can also be (a combination of) "alpha", "colour", "fill", "linetype", "shape" or "size"</p></dd>
2022-08-21 16:59:35 +02:00
</dl></div>
<div class="section level2">
<h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></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>
2023-01-21 23:53:21 +01:00
<p><code>geom_sir()</code> will take any variable from the data that has an <code><a href="as.sir.html">sir</a></code> class (created with <code><a href="as.sir.html">as.sir()</a></code>) using <code><a href="proportion.html">sir_df()</a></code> and will plot bars with the percentage S, I, and R. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis.</p>
<p><code>facet_sir()</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>
2022-08-21 16:59:35 +02:00
<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>
2023-01-21 23:53:21 +01:00
<p><code>scale_sir_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_sir()</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_sir_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_sir()</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>
2022-08-21 16:59:35 +02:00
</div>
</div>
<div class="section level2">
<h2 id="ref-examples">Examples<a class="anchor" aria-label="anchor" href="#ref-examples"></a></h2>
<div class="sourceCode"><pre class="sourceCode r"><code><span class="r-in"><span><span class="co"># \donttest{</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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;&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></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># get antimicrobial results for drugs against a UTI:</span></span></span>
<span class="r-in"><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></span>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">geom_sir</span><span class="op">(</span><span class="op">)</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span><span class="op">}</span></span></span>
2023-01-21 23:53:21 +01:00
<span class="r-plt img"><img src="ggplot_sir-1.png" alt="" width="700" height="433"></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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;&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></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># prettify the plot using some additional functions:</span></span></span>
<span class="r-in"><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></span>
<span class="r-in"><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></span>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">geom_sir</span><span class="op">(</span><span class="op">)</span> <span class="op">+</span></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="fu">scale_y_percent</span><span class="op">(</span><span class="op">)</span> <span class="op">+</span></span></span>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">scale_sir_colours</span><span class="op">(</span><span class="op">)</span> <span class="op">+</span></span></span>
<span class="r-in"><span> <span class="fu">labels_sir_count</span><span class="op">(</span><span class="op">)</span> <span class="op">+</span></span></span>
<span class="r-in"><span> <span class="fu">theme_sir</span><span class="op">(</span><span class="op">)</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span><span class="op">}</span></span></span>
2023-01-21 23:53:21 +01:00
<span class="r-plt img"><img src="ggplot_sir-2.png" alt="" width="700" height="433"></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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;&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></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># or better yet, simplify this using the wrapper function - a single command:</span></span></span>
<span class="r-in"><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></span>
<span class="r-in"><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></span>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">ggplot_sir</span><span class="op">(</span><span class="op">)</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span><span class="op">}</span></span></span>
2023-01-21 23:53:21 +01:00
<span class="r-plt img"><img src="ggplot_sir-3.png" alt="" width="700" height="433"></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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;&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></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># get only proportions and no counts:</span></span></span>
<span class="r-in"><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></span>
<span class="r-in"><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></span>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">ggplot_sir</span><span class="op">(</span>datalabels <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span><span class="op">}</span></span></span>
2023-01-21 23:53:21 +01:00
<span class="r-plt img"><img src="ggplot_sir-4.png" alt="" width="700" height="433"></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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;&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></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># add other ggplot2 arguments as you like:</span></span></span>
<span class="r-in"><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></span>
<span class="r-in"><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></span>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">ggplot_sir</span><span class="op">(</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span> width <span class="op">=</span> <span class="fl">0.5</span>,</span></span>
<span class="r-in"><span> colour <span class="op">=</span> <span class="st">"black"</span>,</span></span>
<span class="r-in"><span> size <span class="op">=</span> <span class="fl">1</span>,</span></span>
<span class="r-in"><span> linetype <span class="op">=</span> <span class="fl">2</span>,</span></span>
<span class="r-in"><span> alpha <span class="op">=</span> <span class="fl">0.25</span></span></span>
<span class="r-in"><span> <span class="op">)</span></span></span>
<span class="r-in"><span><span class="op">}</span></span></span>
2023-01-21 23:53:21 +01:00
<span class="r-plt img"><img src="ggplot_sir-5.png" alt="" width="700" height="433"></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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;&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></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># you can alter the colours with colour names:</span></span></span>
<span class="r-in"><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></span>
<span class="r-in"><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></span>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">ggplot_sir</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></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span><span class="op">}</span></span></span>
2023-01-21 23:53:21 +01:00
<span class="r-plt img"><img src="ggplot_sir-6.png" alt="" width="700" height="433"></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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;&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></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># but you can also use the built-in colour-blind friendly colours for</span></span></span>
<span class="r-in"><span> <span class="co"># your plots, where "S" is green, "I" is yellow and "R" is red:</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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></span></span>
<span class="r-in"><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>,</span></span>
<span class="r-in"><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>,</span></span>
<span class="r-in"><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></span>
<span class="r-in"><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>
2022-08-21 16:59:35 +02:00
<span class="r-in"><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></span>
<span class="r-in"><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></span>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">scale_sir_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></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span><span class="op">}</span></span></span>
2023-01-21 23:53:21 +01:00
<span class="r-plt img"><img src="ggplot_sir-7.png" alt="" width="700" height="433"></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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;&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></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># resistance of ciprofloxacine per age group</span></span></span>
<span class="r-in"><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></span>
<span class="r-in"><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></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span> <span class="fu"><a href="https://dplyr.tidyverse.org/reference/filter.html" class="external-link">filter</a></span><span class="op">(</span></span></span>
<span class="r-in"><span> <span class="va">first_isolate</span> <span class="op">==</span> <span class="cn">TRUE</span>,</span></span>
<span class="r-in"><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">"Escherichia coli"</span><span class="op">)</span></span></span>
<span class="r-in"><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>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># age_groups() is also a function in this AMR package:</span></span></span>
<span class="r-in"><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></span>
<span class="r-in"><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></span>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">ggplot_sir</span><span class="op">(</span>x <span class="op">=</span> <span class="st">"age_group"</span><span class="op">)</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span><span class="op">}</span></span></span>
2024-05-20 21:35:19 +02:00
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>Removed 6 rows containing missing values or values outside the scale range</span>
2024-03-03 23:05:59 +01:00
<span class="r-wrn co"><span class="r-pr">#&gt;</span> (`geom_col()`).</span>
2024-05-20 21:35:19 +02:00
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>Removed 6 rows containing missing values or values outside the scale range</span>
2024-03-03 23:05:59 +01:00
<span class="r-wrn co"><span class="r-pr">#&gt;</span> (`geom_text()`).</span>
2023-01-21 23:53:21 +01:00
<span class="r-plt img"><img src="ggplot_sir-8.png" alt="" width="700" height="433"></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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;&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></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># a shorter version which also adjusts data label colours:</span></span></span>
<span class="r-in"><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></span>
<span class="r-in"><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></span>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">ggplot_sir</span><span class="op">(</span>colours <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span><span class="op">}</span></span></span>
2023-01-21 23:53:21 +01:00
<span class="r-plt img"><img src="ggplot_sir-9.png" alt="" width="700" height="433"></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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;&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></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># it also supports groups (don't forget to use the group var on `x` or `facet`):</span></span></span>
<span class="r-in"><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></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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="va">ward</span> <span class="op">!=</span> <span class="st">"Outpatient"</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>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span> <span class="co"># select only UTI-specific drugs</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><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">ward</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></span>
<span class="r-in"><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">ward</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>
2023-01-21 23:53:21 +01:00
<span class="r-in"><span> <span class="fu">ggplot_sir</span><span class="op">(</span></span></span>
2022-08-28 22:45:38 +02:00
<span class="r-in"><span> x <span class="op">=</span> <span class="st">"ward"</span>,</span></span>
<span class="r-in"><span> facet <span class="op">=</span> <span class="st">"antibiotic"</span>,</span></span>
<span class="r-in"><span> nrow <span class="op">=</span> <span class="fl">1</span>,</span></span>
<span class="r-in"><span> title <span class="op">=</span> <span class="st">"AMR of Anti-UTI Drugs Per Ward"</span>,</span></span>
<span class="r-in"><span> x.title <span class="op">=</span> <span class="st">"Ward"</span>,</span></span>
<span class="r-in"><span> datalabels <span class="op">=</span> <span class="cn">FALSE</span></span></span>
<span class="r-in"><span> <span class="op">)</span></span></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span><span class="op">}</span></span></span>
2022-11-24 20:37:19 +01:00
<span class="r-msg co"><span class="r-pr">#&gt;</span> Using column 'mo' as input for mo_is_gram_negative()</span>
2023-01-21 23:53:21 +01:00
<span class="r-plt img"><img src="ggplot_sir-10.png" alt="" width="700" height="433"></span>
2022-08-21 16:59:35 +02:00
<span class="r-in"><span><span class="co"># }</span></span></span>
</code></pre></div>
</div>
2024-07-16 15:00:55 +02:00
</main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
2022-08-21 16:59:35 +02:00
</nav></aside></div>
<footer><div class="pkgdown-footer-left">
2024-04-23 10:39:01 +02:00
<p><code>AMR</code> (for R). Free and open-source, licenced under the <a target="_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 <a target="_blank" href="https://www.rug.nl" class="external-link">University of Groningen</a> and <a target="_blank" href="https://www.umcg.nl" class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>
2022-08-21 16:59:35 +02:00
</div>
<div class="pkgdown-footer-right">
2024-09-19 14:48:19 +02:00
<p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/assets/logo_rug.svg" style="max-width: 150px;"></a><a target="_blank" href="https://www.umcg.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/assets/logo_umcg.svg" style="max-width: 150px;"></a></p>
2022-08-21 16:59:35 +02:00
</div>
</footer></div>
2024-07-16 15:00:55 +02:00
2022-08-21 16:59:35 +02:00
</body></html>