1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 17:41:59 +02:00

support groups for portion_df, update README

This commit is contained in:
2018-08-12 22:34:03 +02:00
parent e5d32cafe0
commit ce2cdb9309
12 changed files with 215 additions and 100 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -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)

View File

@ -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")
}

View File

@ -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:

View File

@ -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{
# ----------- #