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

467 lines
48 KiB
HTML
Raw Normal View History

2022-08-21 16:59:35 +02:00
<!DOCTYPE html>
2024-02-25 14:46:03 +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"><meta name="description" content="Use these functions to create bar plots for AMR data analysis. All functions rely on ggplot2 functions."><title>AMR Plots with ggplot2 — ggplot_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.8/font.css" rel="stylesheet"><link href="../deps/Fira_Code-0.4.8/font.css" rel="stylesheet"><!-- 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"><!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" 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><!-- 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><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></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 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="@msberends"><!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha25
2022-08-21 16:59:35 +02: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>
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
<nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container">
<a class="navbar-brand me-2" href="../index.html">AMR (for R)</a>
2024-02-25 14:46:03 +01:00
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">2.1.1.9010</small>
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">
2022-08-21 16:59:35 +02:00
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--how-to">
<span class="fa fa-question-circle"></span>
How to
</a>
<div class="dropdown-menu" aria-labelledby="dropdown--how-to">
<a class="dropdown-item" href="../articles/AMR.html">
<span class="fa fa-directions"></span>
2023-01-23 20:14:37 +01:00
Conduct AMR Analysis
2022-08-21 16:59:35 +02:00
</a>
2023-02-08 17:01:47 +01:00
<a class="dropdown-item" href="../reference/antibiogram.html">
<span class="fa fa-file-prescription"></span>
Generate Antibiogram (Trad./Syndromic/WISCA)
</a>
2022-08-21 16:59:35 +02:00
<a class="dropdown-item" href="../articles/resistance_predict.html">
<span class="fa fa-dice"></span>
2023-01-23 20:14:37 +01:00
Predict Antimicrobial Resistance
2022-08-21 16:59:35 +02:00
</a>
<a class="dropdown-item" href="../articles/datasets.html">
<span class="fa fa-database"></span>
2023-02-26 21:34:01 +01:00
Download Data Sets for Own Use
</a>
<a class="dropdown-item" href="../reference/AMR-options.html">
<span class="fa fa-gear"></span>
Set User- Or Team-specific Package Settings
2022-08-21 16:59:35 +02:00
</a>
<a class="dropdown-item" href="../articles/PCA.html">
<span class="fa fa-compress"></span>
2023-01-23 20:14:37 +01:00
Conduct Principal Component Analysis for AMR
2022-08-21 16:59:35 +02:00
</a>
<a class="dropdown-item" href="../articles/MDR.html">
<span class="fa fa-skull-crossbones"></span>
2023-01-23 20:14:37 +01:00
Determine Multi-Drug Resistance (MDR)
2022-08-21 16:59:35 +02:00
</a>
<a class="dropdown-item" href="../articles/WHONET.html">
<span class="fa fa-globe-americas"></span>
2023-01-23 20:14:37 +01:00
Work with WHONET Data
2022-08-21 16:59:35 +02:00
</a>
<a class="dropdown-item" href="../articles/EUCAST.html">
<span class="fa fa-exchange-alt"></span>
2023-01-23 20:14:37 +01:00
Apply Eucast Rules
2022-08-21 16:59:35 +02:00
</a>
<a class="dropdown-item" href="../reference/mo_property.html">
<span class="fa fa-bug"></span>
2023-01-23 20:14:37 +01:00
Get Taxonomy of a Microorganism
2022-08-21 16:59:35 +02:00
</a>
<a class="dropdown-item" href="../reference/ab_property.html">
<span class="fa fa-capsules"></span>
2023-01-23 20:14:37 +01:00
Get Properties of an Antibiotic Drug
2022-08-21 16:59:35 +02:00
</a>
2022-11-13 08:54:32 +01:00
<a class="dropdown-item" href="../reference/av_property.html">
<span class="fa fa-capsules"></span>
2023-01-23 20:14:37 +01:00
Get Properties of an Antiviral Drug
2022-11-13 08:54:32 +01:00
</a>
2022-08-21 16:59:35 +02:00
</div>
</li>
2023-05-24 16:03:18 +02:00
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown--with-other-pkgs">
2023-05-27 10:53:23 +02:00
<span class="fa fa-layer-group"></span>
2023-05-24 16:03:18 +02:00
With other pkgs
</a>
<div class="dropdown-menu" aria-labelledby="dropdown--with-other-pkgs">
<a class="dropdown-item" href="../articles/other_pkg.html">
2023-05-27 10:53:23 +02:00
<span class="fa fa-layer-group"></span>
2023-05-24 16:03:18 +02:00
AMR &amp; dplyr/tidyverse
</a>
<a class="dropdown-item" href="../articles/other_pkg.html">
2023-05-27 10:53:23 +02:00
<span class="fa fa-layer-group"></span>
2023-05-24 16:03:18 +02:00
AMR &amp; data.table
</a>
<a class="dropdown-item" href="../articles/other_pkg.html">
2023-05-27 10:53:23 +02:00
<span class="fa fa-layer-group"></span>
2023-05-24 16:03:18 +02:00
AMR &amp; tidymodels
</a>
<a class="dropdown-item" href="../articles/other_pkg.html">
2023-05-27 10:53:23 +02:00
<span class="fa fa-layer-group"></span>
2023-05-24 16:03:18 +02:00
AMR &amp; base R
</a>
</div>
</li>
2022-08-21 16:59:35 +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>
2023-05-24 16:03:18 +02:00
</ul><form class="form-inline my-2 my-lg-0" role="search">
<input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off"></form>
<ul class="navbar-nav"><li class="nav-item">
2022-08-21 16:59:35 +02:00
<a class="nav-link" href="../news/index.html">
<span class="far fa far fa-newspaper"></span>
Changelog
</a>
</li>
2023-05-24 16:03:18 +02:00
<li class="nav-item">
2022-08-21 16:59:35 +02:00
<a class="external-link nav-link" href="https://github.com/msberends/AMR">
<span class="fab fa fab fa-github"></span>
Source Code
</a>
</li>
</ul></div>
</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>
2023-01-21 23:53:21 +01:00
<small class="dont-index">Source: <a href="https://github.com/msberends/AMR/blob/HEAD/R/ggplot_sir.R" class="external-link"><code>R/ggplot_sir.R</code></a></small>
<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>
<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>
<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>
<dl><dt>data</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
<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>
2023-02-22 14:47:35 +01: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 and I must be merged into one, so the output only consists of S+I vs. R (susceptible vs. resistant) - the default is <code>TRUE</code></p></dd>
2022-08-21 16:59:35 +02:00
<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>
2023-02-22 14:47:35 +01: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 <a href="AMR-options.html">package option</a> <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
<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>
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
<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>
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
<dt>aesthetics</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>
2023-02-10 16:26:36 +01:00
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>Removed 6 rows containing missing values (`position_stack()`).</span>
<span class="r-wrn co"><span class="r-pr">#&gt;</span> <span class="warning">Warning: </span>Removed 6 rows containing missing values (`position_stack()`).</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>
</main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
</nav></aside></div>
<footer><div class="pkgdown-footer-left">
2022-12-11 11:50:34 +01:00
<p></p><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">
2022-12-11 11:50:34 +01:00
<p></p><p><a target="_blank" href="https://www.rug.nl" class="external-link"><img src="https://github.com/msberends/AMR/raw/main/pkgdown/logos/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/logos/logo_umcg.svg" style="max-width: 150px;"></a></p>
2022-08-21 16:59:35 +02:00
</div>
</footer></div>
</body></html>