mirror of
https://github.com/msberends/AMR.git
synced 2024-12-25 18:06:12 +01:00
support groups for portion_df, update README
This commit is contained in:
parent
e5d32cafe0
commit
ce2cdb9309
@ -120,12 +120,14 @@ importFrom(dplyr,arrange)
|
||||
importFrom(dplyr,arrange_at)
|
||||
importFrom(dplyr,as_tibble)
|
||||
importFrom(dplyr,between)
|
||||
importFrom(dplyr,bind_cols)
|
||||
importFrom(dplyr,bind_rows)
|
||||
importFrom(dplyr,case_when)
|
||||
importFrom(dplyr,desc)
|
||||
importFrom(dplyr,everything)
|
||||
importFrom(dplyr,filter)
|
||||
importFrom(dplyr,group_by)
|
||||
importFrom(dplyr,group_by_at)
|
||||
importFrom(dplyr,group_vars)
|
||||
importFrom(dplyr,if_else)
|
||||
importFrom(dplyr,lag)
|
||||
importFrom(dplyr,left_join)
|
||||
|
4
R/data.R
4
R/data.R
@ -279,11 +279,11 @@
|
||||
|
||||
#' Dataset with 2000 blood culture isolates of septic patients
|
||||
#'
|
||||
#' An anonymised dataset containing 2000 microbial blood culture isolates with their antibiogram of septic patients found in 5 different hospitals in the Netherlands, between 2001 and 2017. This data.frame can be used to practice AMR analysis. For examples, press F1.
|
||||
#' An anonymised dataset containing 2000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. It is true, genuine data. This \code{data.frame} can be used to practice AMR analysis. For examples, press F1.
|
||||
#' @format A data.frame with 2000 observations and 49 variables:
|
||||
#' \describe{
|
||||
#' \item{\code{date}}{date of receipt at the laboratory}
|
||||
#' \item{\code{hospital_id}}{ID of the hospital}
|
||||
#' \item{\code{hospital_id}}{ID of the hospital, from A to D}
|
||||
#' \item{\code{ward_icu}}{logical to determine if ward is an intensive care unit}
|
||||
#' \item{\code{ward_clinical}}{logical to determine if ward is a regular clinical ward}
|
||||
#' \item{\code{ward_outpatient}}{logical to determine if ward is an outpatient clinic}
|
||||
|
@ -55,7 +55,7 @@
|
||||
#' @return A vector to add to table, see Examples.
|
||||
#' @source Methodology of this function is based on: \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition}, 2014, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
|
||||
#' @examples
|
||||
#' # septic_patients is a dataset available in the AMR package. It is true data.
|
||||
#' # septic_patients is a dataset available in the AMR package. It is true, genuine data.
|
||||
#' ?septic_patients
|
||||
#'
|
||||
#' library(dplyr)
|
||||
|
@ -21,8 +21,9 @@
|
||||
#' Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal \code{\link[ggplot2]{ggplot}} functions.
|
||||
#' @param data a \code{data.frame} with column(s) of class \code{"rsi"} (see \code{\link{as.rsi}})
|
||||
#' @param position position adjustment of bars, either \code{"stack"} (default) or \code{"dodge"}
|
||||
#' @param x parameter to show on x axis, either \code{"Antibiotic"} (default) or \code{"Interpretation"}
|
||||
#' @param facet parameter to split plots by, either \code{"Interpretation"} (default) or \code{"Antibiotic"}
|
||||
#' @param x variable to show on x axis, either \code{"Antibiotic"} (default) or \code{"Interpretation"}
|
||||
#' @param fill variable to categorise using the plots legend
|
||||
#' @param facet variable to split plots by, either \code{"Interpretation"} (default) or \code{"Antibiotic"}
|
||||
#' @details At default, the names of antibiotics will be shown on the plots using \code{\link{abname}}. This can be set with the option \code{get_antibiotic_names} (a logical value), so change it e.g. to \code{FALSE} with \code{options(get_antibiotic_names = FALSE)}.
|
||||
#'
|
||||
#' \strong{The functions}\cr
|
||||
@ -64,8 +65,18 @@
|
||||
#' septic_patients %>%
|
||||
#' select(amox, nitr, fosf, trim, cipr) %>%
|
||||
#' ggplot_rsi(x = "Interpretation", facet = "Antibiotic")
|
||||
#'
|
||||
#' # it also supports groups (don't forget to use facet on the group):
|
||||
#' septic_patients %>%
|
||||
#' select(hospital_id, amox, cipr) %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' ggplot_rsi() +
|
||||
#' facet_grid("hospital_id") +
|
||||
#' labs(title = "AMR of Amoxicillin And Ciprofloxacine Per Hospital")
|
||||
ggplot_rsi <- function(data,
|
||||
position = "stack",
|
||||
x = "Antibiotic",
|
||||
fill = "Interpretation",
|
||||
facet = NULL) {
|
||||
|
||||
if (!"ggplot2" %in% rownames(installed.packages())) {
|
||||
@ -73,11 +84,15 @@ ggplot_rsi <- function(data,
|
||||
}
|
||||
|
||||
p <- ggplot2::ggplot(data = data) +
|
||||
geom_rsi(x = x) +
|
||||
geom_rsi(position = position, x = x, fill = fill) +
|
||||
scale_y_percent() +
|
||||
scale_rsi_colours() +
|
||||
theme_rsi()
|
||||
|
||||
if (fill == "Interpretation") {
|
||||
# set RSI colours
|
||||
p <- p + scale_rsi_colours()
|
||||
}
|
||||
|
||||
if (!is.null(facet)) {
|
||||
p <- p + facet_rsi(facet = facet)
|
||||
}
|
||||
@ -87,7 +102,7 @@ ggplot_rsi <- function(data,
|
||||
|
||||
#' @rdname ggplot_rsi
|
||||
#' @export
|
||||
geom_rsi <- function(position = "stack", x = c("Antibiotic", "Interpretation")) {
|
||||
geom_rsi <- function(position = "stack", x = c("Antibiotic", "Interpretation"), fill = "Interpretation") {
|
||||
|
||||
x <- x[1]
|
||||
if (!x %in% c("Antibiotic", "Interpretation")) {
|
||||
@ -95,8 +110,8 @@ geom_rsi <- function(position = "stack", x = c("Antibiotic", "Interpretation"))
|
||||
}
|
||||
|
||||
ggplot2::layer(geom = "bar", stat = "identity", position = position,
|
||||
mapping = ggplot2::aes_string(x = x, y = "Percentage", fill = "Interpretation"),
|
||||
data = AMR::portion_df, params = list())
|
||||
mapping = ggplot2::aes_string(x = x, y = "Percentage", fill = fill),
|
||||
data = AMR::portion_df, params = list())
|
||||
|
||||
}
|
||||
|
||||
|
55
R/portion.R
55
R/portion.R
@ -29,7 +29,7 @@
|
||||
#' @param translate a logical value to indicate whether antibiotic abbreviations should be translated with \code{\link{abname}}
|
||||
#' @details \strong{Remember that you should filter your table to let it contain only first isolates!} Use \code{\link{first_isolate}} to determine them in your data set.
|
||||
#'
|
||||
#' \code{portion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the portions R, I and S. The resulting \code{data.frame} will have three rows (for R/I/S) and a column for each variable with class \code{"rsi"}.
|
||||
#' \code{portion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the portions R, I and S. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each variable with class \code{"rsi"}.
|
||||
#'
|
||||
#' The old \code{\link{rsi}} function is still available for backwards compatibility but is deprecated.
|
||||
#' \if{html}{
|
||||
@ -45,6 +45,8 @@
|
||||
#' \out{<div style="text-align: center">}\figure{combi_therapy_3.png}\out{</div>}
|
||||
#' }
|
||||
#' @source \strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition}, 2014, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
|
||||
#'
|
||||
#' Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html}
|
||||
#' @seealso \code{\link{n_rsi}} to count cases with antimicrobial results.
|
||||
#' @keywords resistance susceptibility rsi_df rsi antibiotics isolate isolates
|
||||
#' @return Double or, when \code{as_percent = TRUE}, a character.
|
||||
@ -52,6 +54,9 @@
|
||||
#' @name portion
|
||||
#' @export
|
||||
#' @examples
|
||||
#' # septic_patients is a data set available in the AMR package. It is true, genuine data.
|
||||
#' ?septic_patients
|
||||
#'
|
||||
#' # Calculate resistance
|
||||
#' portion_R(septic_patients$amox)
|
||||
#' portion_IR(septic_patients$amox)
|
||||
@ -100,6 +105,18 @@
|
||||
#' combination_p = portion_S(cipr, gent, as_percent = TRUE),
|
||||
#' combination_n = n_rsi(cipr, gent))
|
||||
#'
|
||||
#' # Get portions S/I/R immediately of all rsi columns
|
||||
#' septic_patients %>%
|
||||
#' select(amox, cipr) %>%
|
||||
#' portion_df(translate = FALSE)
|
||||
#'
|
||||
#' # It also supports grouping variables
|
||||
#' septic_patients %>%
|
||||
#' select(hospital_id, amox, cipr) %>%
|
||||
#' group_by(hospital_id) %>%
|
||||
#' portion_df(translate = FALSE)
|
||||
#'
|
||||
#'
|
||||
#' \dontrun{
|
||||
#'
|
||||
#' # calculate current empiric combination therapy of Helicobacter gastritis:
|
||||
@ -177,25 +194,33 @@ portion_S <- function(ab1,
|
||||
}
|
||||
|
||||
#' @rdname portion
|
||||
#' @importFrom dplyr bind_cols summarise_if mutate
|
||||
#' @importFrom dplyr bind_rows summarise_if mutate group_vars select everything
|
||||
#' @export
|
||||
portion_df <- function(data, translate = getOption("get_antibiotic_names", TRUE)) {
|
||||
resS <- bind_cols(data.frame(Interpretation = "S", stringsAsFactors = FALSE),
|
||||
summarise_if(.tbl = data,
|
||||
.predicate = is.rsi,
|
||||
.funs = portion_S))
|
||||
resI <- bind_cols(data.frame(Interpretation = "I", stringsAsFactors = FALSE),
|
||||
summarise_if(.tbl = data,
|
||||
.predicate = is.rsi,
|
||||
.funs = portion_I))
|
||||
resR <- bind_cols(data.frame(Interpretation = "R", stringsAsFactors = FALSE),
|
||||
summarise_if(.tbl = data,
|
||||
.predicate = is.rsi,
|
||||
.funs = portion_R))
|
||||
|
||||
resS <- summarise_if(.tbl = data,
|
||||
.predicate = is.rsi,
|
||||
.funs = portion_S) %>%
|
||||
mutate(Interpretation = "S") %>%
|
||||
select(Interpretation, everything())
|
||||
|
||||
resI <- summarise_if(.tbl = data,
|
||||
.predicate = is.rsi,
|
||||
.funs = portion_I) %>%
|
||||
mutate(Interpretation = "I") %>%
|
||||
select(Interpretation, everything())
|
||||
|
||||
resR <- summarise_if(.tbl = data,
|
||||
.predicate = is.rsi,
|
||||
.funs = portion_R) %>%
|
||||
mutate(Interpretation = "R") %>%
|
||||
select(Interpretation, everything())
|
||||
|
||||
data.groups <- group_vars(data)
|
||||
|
||||
res <- bind_rows(resS, resI, resR) %>%
|
||||
mutate(Interpretation = factor(Interpretation, levels = c("R", "I", "S"), ordered = TRUE)) %>%
|
||||
tidyr::gather(Antibiotic, Percentage, -Interpretation)
|
||||
tidyr::gather(Antibiotic, Percentage, -Interpretation, -data.groups)
|
||||
if (translate == TRUE) {
|
||||
res <- res %>% mutate(Antibiotic = abname(Antibiotic, from = "guess", to = "official"))
|
||||
}
|
||||
|
163
README.md
163
README.md
@ -24,6 +24,19 @@ Erwin E.A. Hassing<sup>2</sup>,
|
||||
<a href="http://www.eurhealth-1health.eu"><img src="man/figures/logo_eh1h.png" height="60px"></a>
|
||||
<a href="http://www.eurhealth-1health.eu"><img src="man/figures/logo_interreg.png" height="60px"></a>
|
||||
|
||||
## Contents
|
||||
* [Why this package?](#why-this-package)
|
||||
* [How to get it?](#how-to-get-it)
|
||||
* [Install from CRAN](#install-from-cran)
|
||||
* [Install from GitHub](#install-from-github)
|
||||
* [How to use it?](#how-to-use-it)
|
||||
* [New classes](#new-classes)
|
||||
* [Overwrite/force resistance based on EUCAST rules](#overwriteforce-resistance-based-on-eucast-rules)
|
||||
* [Other (microbial) epidemiological functions](#other-microbial-epidemiological-functions)
|
||||
* [Frequency tables](#frequency-tables)
|
||||
* [Data sets included in package](#data-sets-included-in-package)
|
||||
* [Copyright](#copyright)
|
||||
|
||||
## Why this package?
|
||||
This R package was intended to make microbial epidemiology easier. Most functions contain extensive help pages to get started.
|
||||
|
||||
@ -50,12 +63,12 @@ And it contains:
|
||||
|
||||
With the `MDRO` function (abbreviation of Multi Drug Resistant Organisms), you can check your isolates for exceptional resistance with country-specific guidelines or EUCAST rules. Currently guidelines for Germany and the Netherlands are supported. Please suggest addition of your own country here: [https://github.com/msberends/AMR/issues/new](https://github.com/msberends/AMR/issues/new?title=New%20guideline%20for%20MDRO&body=%3C--%20Please%20add%20your%20country%20code,%20guideline%20name,%20version%20and%20source%20below%20and%20remove%20this%20line--%3E).
|
||||
|
||||
#### Read all changes and new functions in [NEWS.md](NEWS.md).
|
||||
**Read all changes and new functions in [NEWS.md](NEWS.md).**
|
||||
|
||||
## How to get it?
|
||||
This package [is published on CRAN](http://cran.r-project.org/package=AMR), the official R network.
|
||||
|
||||
### Install from CRAN (recommended)
|
||||
### Install from CRAN
|
||||
[![CRAN_Badge](https://img.shields.io/cran/v/AMR.svg?label=CRAN&colorB=3679BC)](http://cran.r-project.org/package=AMR) [![CRAN_Downloads](https://cranlogs.r-pkg.org/badges/grand-total/AMR)](http://cran.r-project.org/package=AMR)
|
||||
|
||||
(Note: Downloads measured only by [cran.rstudio.com](https://cran.rstudio.com/package=AMR), this excludes e.g. the official [cran.r-project.org](https://cran.r-project.org/package=AMR))
|
||||
@ -67,7 +80,7 @@ This package [is published on CRAN](http://cran.r-project.org/package=AMR), the
|
||||
- <img src="https://cran.r-project.org/favicon.ico" alt="R favicon" height="20px"> Install in R directly:
|
||||
- `install.packages("AMR")`
|
||||
|
||||
### Install from GitHub (latest development version)
|
||||
### Install from GitHub
|
||||
[![Travis_Build](https://travis-ci.org/msberends/AMR.svg?branch=master)](https://travis-ci.org/msberends/AMR)
|
||||
[![Since_Release](https://img.shields.io/github/commits-since/msberends/AMR/latest.svg?colorB=3679BC)](https://github.com/msberends/AMR/commits/master)
|
||||
[![Last_Commit](https://img.shields.io/github/last-commit/msberends/AMR.svg)](https://github.com/msberends/AMR/commits/master)
|
||||
@ -86,6 +99,85 @@ library(AMR)
|
||||
# For a list of functions:
|
||||
help(package = "AMR")
|
||||
```
|
||||
|
||||
### New classes
|
||||
This package contains two new S3 classes: `mic` for MIC values (e.g. from Vitek or Phoenix) and `rsi` for antimicrobial drug interpretations (i.e. S, I and R). Both are actually ordered factors under the hood (an MIC of `2` being higher than `<=1` but lower than `>=32`, and for class `rsi` factors are ordered as `S < I < R`).
|
||||
Both classes have extensions for existing generic functions like `print`, `summary` and `plot`.
|
||||
|
||||
These functions also try to coerce valid values.
|
||||
|
||||
#### RSI
|
||||
The `septic_patients` data set comes with antimicrobial results of more than 40 different drugs. For example, columns `amox` and `cipr` contain results of amoxicillin and ciprofloxacin, respectively.
|
||||
```r
|
||||
summary(septic_patients[, c("amox", "cipr")])
|
||||
# amox cipr
|
||||
# Mode :rsi Mode :rsi
|
||||
# <NA> :1002 <NA> :596
|
||||
# Sum S :336 Sum S :1108
|
||||
# Sum IR:662 Sum IR:296
|
||||
# -Sum R:659 -Sum R:227
|
||||
# -Sum I:3 -Sum I:69
|
||||
```
|
||||
|
||||
You can use the `plot` function from base R:
|
||||
```r
|
||||
plot(septic_patients$cipr)
|
||||
```
|
||||
|
||||
![example_1_rsi](man/figures/rsi_example1.png)
|
||||
|
||||
Or use the `ggplot2` and `dplyr` packages to create more appealing plots:
|
||||
```r
|
||||
library(dplyr)
|
||||
library(ggplot2)
|
||||
|
||||
septic_patients %>%
|
||||
select(amox, cipr) %>%
|
||||
ggplot_rsi()
|
||||
```
|
||||
|
||||
![example_2_rsi](man/figures/rsi_example2.png)
|
||||
|
||||
```r
|
||||
septic_patients %>%
|
||||
select(amox, cipr) %>%
|
||||
ggplot_rsi(x = "Interpretation", facet = "Antibiotic")
|
||||
```
|
||||
|
||||
![example_3_rsi](man/figures/rsi_example3.png)
|
||||
|
||||
It also supports grouping variables. Let's say we want to compare resistance of these antibiotics between hospitals A to D (variable `hospital_id`):
|
||||
|
||||
```r
|
||||
septic_patients %>%
|
||||
select(hospital_id, amox, cipr) %>%
|
||||
group_by(hospital_id) %>%
|
||||
ggplot_rsi() + # start adding ggplot elements here with `+`
|
||||
facet_grid("hospital_id") + # splitting the plots on our grouping variable
|
||||
labs(title = "AMR of Amoxicillin And Ciprofloxacine Per Hospital")
|
||||
```
|
||||
|
||||
![example_4_rsi](man/figures/rsi_example4.png)
|
||||
|
||||
You could use this to group on anything in your plots: Gram stain, age (group), genus, geographic location, et cetera.
|
||||
|
||||
#### MIC
|
||||
|
||||
```r
|
||||
# Transform values to new class
|
||||
mic_data <- as.mic(c(">=32", "1.0", "8", "<=0.128", "8", "16", "16"))
|
||||
|
||||
summary(mic_data)
|
||||
# Mode:mic
|
||||
# <NA>:0
|
||||
# Min.:<=0.128
|
||||
# Max.:>=32
|
||||
|
||||
plot(mic_data)
|
||||
```
|
||||
![example_mic](man/figures/mic_example.png)
|
||||
|
||||
|
||||
### Overwrite/force resistance based on EUCAST rules
|
||||
This is also called *interpretive reading*.
|
||||
```r
|
||||
@ -132,69 +224,12 @@ guess_bactid("VISA") # Vancomycin Intermediate S. aureus
|
||||
guess_bactid("VRSA") # Vancomycin Resistant S. aureus
|
||||
```
|
||||
|
||||
### New classes
|
||||
This package contains two new S3 classes: `mic` for MIC values (e.g. from Vitek or Phoenix) and `rsi` for antimicrobial drug interpretations (i.e. S, I and R). Both are actually ordered factors under the hood (an MIC of `2` being higher than `<=1` but lower than `>=32`, and for class `rsi` factors are ordered as `S < I < R`).
|
||||
Both classes have extensions for existing generic functions like `print`, `summary` and `plot`.
|
||||
|
||||
These functions also try to coerce valid values.
|
||||
|
||||
#### RSI
|
||||
The `septic_patients` data set comes with antimicrobial results of more than 40 different drugs. For example, columns `amox` and `cipr` contain results of amoxicillin and ciprofloxacin, respectively.
|
||||
```r
|
||||
summary(septic_patients[, c("amox", "cipr")])
|
||||
# amox cipr
|
||||
# Mode :rsi Mode :rsi
|
||||
# <NA> :1002 <NA> :596
|
||||
# Sum S :336 Sum S :1108
|
||||
# Sum IR:662 Sum IR:296
|
||||
# -Sum R:659 -Sum R:227
|
||||
# -Sum I:3 -Sum I:69
|
||||
```
|
||||
|
||||
You can use the `plot` function from base R:
|
||||
```r
|
||||
plot(septic_patients$cipr)
|
||||
```
|
||||
|
||||
![example_1_rsi](man/figures/rsi_example1.png)
|
||||
|
||||
Or use the `ggplot2` and `dplyr` packages to create more appealing plots:
|
||||
```r
|
||||
septic_patients %>%
|
||||
select(amox, cipr) %>%
|
||||
ggplot_rsi()
|
||||
```
|
||||
|
||||
![example_2_rsi](man/figures/rsi_example2.png)
|
||||
### Other (microbial) epidemiological functions
|
||||
|
||||
```r
|
||||
septic_patients %>%
|
||||
select(amox, cipr) %>%
|
||||
ggplot_rsi(x = "Interpretation", facet = "Antibiotic")
|
||||
```
|
||||
# G-test to replace Chi squared test
|
||||
g.test(...)
|
||||
|
||||
![example_3_rsi](man/figures/rsi_example3.png)
|
||||
|
||||
|
||||
#### MIC
|
||||
|
||||
```r
|
||||
# Transform values to new class
|
||||
mic_data <- as.mic(c(">=32", "1.0", "8", "<=0.128", "8", "16", "16"))
|
||||
|
||||
summary(mic_data)
|
||||
# Mode:mic
|
||||
# <NA>:0
|
||||
# Min.:<=0.128
|
||||
# Max.:>=32
|
||||
|
||||
plot(mic_data)
|
||||
```
|
||||
![example_mic](man/figures/mic_example.png)
|
||||
|
||||
Other epidemiological functions:
|
||||
|
||||
```r
|
||||
# Determine key antibiotic based on bacteria ID
|
||||
key_antibiotics(...)
|
||||
|
||||
@ -318,7 +353,7 @@ Learn more about this function with:
|
||||
?freq
|
||||
```
|
||||
|
||||
### Databases included in package
|
||||
### Data sets included in package
|
||||
Datasets to work with antibiotics and bacteria properties.
|
||||
```r
|
||||
# Dataset with 2000 random blood culture isolates from anonymised
|
||||
|
BIN
man/figures/rsi_example4.png
Normal file
BIN
man/figures/rsi_example4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
@ -76,7 +76,7 @@ Determine first (weighted) isolates of all microorganisms of every patient per e
|
||||
}
|
||||
|
||||
\examples{
|
||||
# septic_patients is a dataset available in the AMR package. It is true data.
|
||||
# septic_patients is a dataset available in the AMR package. It is true, genuine data.
|
||||
?septic_patients
|
||||
|
||||
library(dplyr)
|
||||
|
@ -9,9 +9,11 @@
|
||||
\alias{theme_rsi}
|
||||
\title{AMR bar plots with \code{ggplot}}
|
||||
\usage{
|
||||
ggplot_rsi(data, x = "Antibiotic", facet = NULL)
|
||||
ggplot_rsi(data, position = "stack", x = "Antibiotic",
|
||||
fill = "Interpretation", facet = NULL)
|
||||
|
||||
geom_rsi(position = "stack", x = c("Antibiotic", "Interpretation"))
|
||||
geom_rsi(position = "stack", x = c("Antibiotic", "Interpretation"),
|
||||
fill = "Interpretation")
|
||||
|
||||
facet_rsi(facet = c("Interpretation", "Antibiotic"))
|
||||
|
||||
@ -24,11 +26,13 @@ theme_rsi()
|
||||
\arguments{
|
||||
\item{data}{a \code{data.frame} with column(s) of class \code{"rsi"} (see \code{\link{as.rsi}})}
|
||||
|
||||
\item{x}{parameter to show on x axis, either \code{"Antibiotic"} (default) or \code{"Interpretation"}}
|
||||
|
||||
\item{facet}{parameter to split plots by, either \code{"Interpretation"} (default) or \code{"Antibiotic"}}
|
||||
|
||||
\item{position}{position adjustment of bars, either \code{"stack"} (default) or \code{"dodge"}}
|
||||
|
||||
\item{x}{variable to show on x axis, either \code{"Antibiotic"} (default) or \code{"Interpretation"}}
|
||||
|
||||
\item{fill}{variable to categorise using the plots legend}
|
||||
|
||||
\item{facet}{variable to split plots by, either \code{"Interpretation"} (default) or \code{"Antibiotic"}}
|
||||
}
|
||||
\description{
|
||||
Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal \code{\link[ggplot2]{ggplot}} functions.
|
||||
@ -74,4 +78,12 @@ septic_patients \%>\%
|
||||
septic_patients \%>\%
|
||||
select(amox, nitr, fosf, trim, cipr) \%>\%
|
||||
ggplot_rsi(x = "Interpretation", facet = "Antibiotic")
|
||||
|
||||
# it also supports groups (don't forget to use facet on the group):
|
||||
septic_patients \%>\%
|
||||
select(hospital_id, amox, cipr) \%>\%
|
||||
group_by(hospital_id) \%>\%
|
||||
ggplot_rsi() +
|
||||
facet_grid("hospital_id") +
|
||||
labs(title = "AMR of Amoxicillin And Ciprofloxacine Per Hospital")
|
||||
}
|
||||
|
@ -11,6 +11,8 @@
|
||||
\title{Calculate resistance of isolates}
|
||||
\source{
|
||||
\strong{M39 Analysis and Presentation of Cumulative Antimicrobial Susceptibility Test Data, 4th Edition}, 2014, \emph{Clinical and Laboratory Standards Institute (CLSI)}. \url{https://clsi.org/standards/products/microbiology/documents/m39/}.
|
||||
|
||||
Wickham H. \strong{Tidy Data.} The Journal of Statistical Software, vol. 59, 2014. \url{http://vita.had.co.nz/papers/tidy-data.html}
|
||||
}
|
||||
\usage{
|
||||
portion_R(ab1, ab2 = NULL, minimum = 30, as_percent = FALSE)
|
||||
@ -49,7 +51,7 @@ These functions can be used to calculate the (co-)resistance of microbial isolat
|
||||
\details{
|
||||
\strong{Remember that you should filter your table to let it contain only first isolates!} Use \code{\link{first_isolate}} to determine them in your data set.
|
||||
|
||||
\code{portion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the portions R, I and S. The resulting \code{data.frame} will have three rows (for R/I/S) and a column for each variable with class \code{"rsi"}.
|
||||
\code{portion_df} takes any variable from \code{data} that has an \code{"rsi"} class (created with \code{\link{as.rsi}}) and calculates the portions R, I and S. The resulting \emph{tidy data} (see Source) \code{data.frame} will have three rows (S/I/R) and a column for each variable with class \code{"rsi"}.
|
||||
|
||||
The old \code{\link{rsi}} function is still available for backwards compatibility but is deprecated.
|
||||
\if{html}{
|
||||
@ -66,6 +68,9 @@ The old \code{\link{rsi}} function is still available for backwards compatibilit
|
||||
}
|
||||
}
|
||||
\examples{
|
||||
# septic_patients is a data set available in the AMR package. It is true, genuine data.
|
||||
?septic_patients
|
||||
|
||||
# Calculate resistance
|
||||
portion_R(septic_patients$amox)
|
||||
portion_IR(septic_patients$amox)
|
||||
@ -114,6 +119,18 @@ septic_patients \%>\%
|
||||
combination_p = portion_S(cipr, gent, as_percent = TRUE),
|
||||
combination_n = n_rsi(cipr, gent))
|
||||
|
||||
# Get portions S/I/R immediately of all rsi columns
|
||||
septic_patients \%>\%
|
||||
select(amox, cipr) \%>\%
|
||||
portion_df(translate = FALSE)
|
||||
|
||||
# It also supports grouping variables
|
||||
septic_patients \%>\%
|
||||
select(hospital_id, amox, cipr) \%>\%
|
||||
group_by(hospital_id) \%>\%
|
||||
portion_df(translate = FALSE)
|
||||
|
||||
|
||||
\dontrun{
|
||||
|
||||
# calculate current empiric combination therapy of Helicobacter gastritis:
|
||||
|
@ -7,7 +7,7 @@
|
||||
\format{A data.frame with 2000 observations and 49 variables:
|
||||
\describe{
|
||||
\item{\code{date}}{date of receipt at the laboratory}
|
||||
\item{\code{hospital_id}}{ID of the hospital}
|
||||
\item{\code{hospital_id}}{ID of the hospital, from A to D}
|
||||
\item{\code{ward_icu}}{logical to determine if ward is an intensive care unit}
|
||||
\item{\code{ward_clinical}}{logical to determine if ward is a regular clinical ward}
|
||||
\item{\code{ward_outpatient}}{logical to determine if ward is an outpatient clinic}
|
||||
@ -21,7 +21,7 @@
|
||||
septic_patients
|
||||
}
|
||||
\description{
|
||||
An anonymised dataset containing 2000 microbial blood culture isolates with their antibiogram of septic patients found in 5 different hospitals in the Netherlands, between 2001 and 2017. This data.frame can be used to practice AMR analysis. For examples, press F1.
|
||||
An anonymised dataset containing 2000 microbial blood culture isolates with their full antibiograms found in septic patients in 4 different hospitals in the Netherlands, between 2001 and 2017. It is true, genuine data. This \code{data.frame} can be used to practice AMR analysis. For examples, press F1.
|
||||
}
|
||||
\examples{
|
||||
# ----------- #
|
||||
|
@ -32,4 +32,13 @@ test_that("ggplot_rsi works", {
|
||||
expect_error(geom_rsi(x = "test"))
|
||||
expect_error(facet_rsi(facet = "test"))
|
||||
|
||||
# support for groups
|
||||
print(
|
||||
septic_patients %>%
|
||||
select(hospital_id, amox, cipr) %>%
|
||||
group_by(hospital_id) %>%
|
||||
ggplot_rsi() +
|
||||
facet_grid("hospital_id")
|
||||
)
|
||||
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user