mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 00:02:38 +02:00
new ggplot enhancement
This commit is contained in:
@ -7,8 +7,8 @@
|
||||
\code{\link{antibiotics}}
|
||||
}
|
||||
\usage{
|
||||
abname(abcode, from = c("guess", "atc", "molis", "umcg"), to = "official",
|
||||
textbetween = " + ", tolower = FALSE)
|
||||
abname(abcode, from = c("guess", "atc", "molis", "umcg"),
|
||||
to = "official", textbetween = " + ", tolower = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{abcode}{a code or name, like \code{"AMOX"}, \code{"AMCL"} or \code{"J01CA04"}}
|
||||
|
@ -9,10 +9,11 @@ Methodology of this function is based on: \strong{M39 Analysis and Presentation
|
||||
\usage{
|
||||
first_isolate(tbl, col_date, col_patient_id, col_bactid = NA,
|
||||
col_testcode = NA, col_specimen = NA, col_icu = NA,
|
||||
col_keyantibiotics = NA, episode_days = 365, testcodes_exclude = "",
|
||||
icu_exclude = FALSE, filter_specimen = NA, output_logical = TRUE,
|
||||
type = "keyantibiotics", ignore_I = TRUE, points_threshold = 2,
|
||||
info = TRUE, col_genus = NA, col_species = NA)
|
||||
col_keyantibiotics = NA, episode_days = 365,
|
||||
testcodes_exclude = "", icu_exclude = FALSE, filter_specimen = NA,
|
||||
output_logical = TRUE, type = "keyantibiotics", ignore_I = TRUE,
|
||||
points_threshold = 2, info = TRUE, col_genus = NA,
|
||||
col_species = NA)
|
||||
}
|
||||
\arguments{
|
||||
\item{tbl}{a \code{data.frame} containing isolates.}
|
||||
|
10
man/freq.Rd
10
man/freq.Rd
@ -7,9 +7,9 @@
|
||||
\alias{print.frequency_tbl}
|
||||
\title{Frequency table}
|
||||
\usage{
|
||||
frequency_tbl(x, ..., sort.count = TRUE, nmax = getOption("max.print.freq"),
|
||||
na.rm = TRUE, row.names = TRUE, markdown = FALSE, digits = 2,
|
||||
sep = " ")
|
||||
frequency_tbl(x, ..., sort.count = TRUE,
|
||||
nmax = getOption("max.print.freq"), na.rm = TRUE, row.names = TRUE,
|
||||
markdown = FALSE, digits = 2, sep = " ")
|
||||
|
||||
freq(x, ..., sort.count = TRUE, nmax = getOption("max.print.freq"),
|
||||
na.rm = TRUE, row.names = TRUE, markdown = FALSE, digits = 2,
|
||||
@ -17,8 +17,8 @@ freq(x, ..., sort.count = TRUE, nmax = getOption("max.print.freq"),
|
||||
|
||||
top_freq(f, n)
|
||||
|
||||
\method{print}{frequency_tbl}(x, nmax = getOption("max.print.freq", default =
|
||||
15), ...)
|
||||
\method{print}{frequency_tbl}(x, nmax = getOption("max.print.freq",
|
||||
default = 15), ...)
|
||||
}
|
||||
\arguments{
|
||||
\item{x}{vector of any class or a \code{\link{data.frame}}, \code{\link{tibble}} or \code{\link{table}}}
|
||||
|
@ -12,7 +12,8 @@ This code is almost identical to \code{\link{chisq.test}}, except that:
|
||||
}
|
||||
}
|
||||
\usage{
|
||||
g.test(x, y = NULL, p = rep(1/length(x), length(x)), rescale.p = FALSE)
|
||||
g.test(x, y = NULL, p = rep(1/length(x), length(x)),
|
||||
rescale.p = FALSE)
|
||||
}
|
||||
\arguments{
|
||||
\item{x}{a numeric vector or matrix. \code{x} and \code{y} can also
|
||||
|
77
man/ggplot_rsi.Rd
Normal file
77
man/ggplot_rsi.Rd
Normal file
@ -0,0 +1,77 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/ggplot_rsi.R
|
||||
\name{ggplot_rsi}
|
||||
\alias{ggplot_rsi}
|
||||
\alias{geom_rsi}
|
||||
\alias{facet_rsi}
|
||||
\alias{scale_y_percent}
|
||||
\alias{scale_rsi_colours}
|
||||
\alias{theme_rsi}
|
||||
\title{AMR bar plots with \code{ggplot}}
|
||||
\usage{
|
||||
ggplot_rsi(data, x = "Antibiotic", facet = NULL)
|
||||
|
||||
geom_rsi(position = "stack", x = c("Antibiotic", "Interpretation"))
|
||||
|
||||
facet_rsi(facet = c("Interpretation", "Antibiotic"))
|
||||
|
||||
scale_y_percent()
|
||||
|
||||
scale_rsi_colours()
|
||||
|
||||
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"}}
|
||||
}
|
||||
\description{
|
||||
Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal \code{\link{ggplot}} functions.
|
||||
}
|
||||
\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
|
||||
\code{geom_rsi} will take any variable from the data that has an \code{rsi} class (created with \code{\link{as.rsi}}) using \code{\link{portion_df}} and will plot bars with the percentage R, I and S. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis.
|
||||
|
||||
\code{facet_rsi} creates 2d plots (at default based on S/I/R) using \code{\link{facet_wrap}}.
|
||||
|
||||
\code{scale_y_percent} transforms the y axis to a 0 to 100% range.
|
||||
|
||||
\code{scale_rsi_colours} sets colours to the bars: green for S, yellow for I and red for R.
|
||||
|
||||
\code{theme_rsi} is a \code{\link{theme}} with minimal distraction.
|
||||
|
||||
\code{ggplot_rsi} 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{\%>\%}). See Examples.
|
||||
}
|
||||
\examples{
|
||||
library(dplyr)
|
||||
library(ggplot2)
|
||||
|
||||
# get antimicrobial results for drugs against a UTI:
|
||||
ggplot(septic_patients \%>\% select(amox, nitr, fosf, trim, cipr)) +
|
||||
geom_rsi()
|
||||
|
||||
# prettify it using some additional functions
|
||||
df <- septic_patients[, c("amox", "nitr", "fosf", "trim", "cipr")]
|
||||
ggplot(df) +
|
||||
geom_rsi(x = "Interpretation") +
|
||||
facet_rsi(facet = "Antibiotic") +
|
||||
scale_y_percent() +
|
||||
scale_rsi_colours() +
|
||||
theme_rsi()
|
||||
|
||||
# or better yet, simplify this using the wrapper function - a single command:
|
||||
septic_patients \%>\%
|
||||
select(amox, nitr, fosf, trim, cipr) \%>\%
|
||||
ggplot_rsi()
|
||||
|
||||
septic_patients \%>\%
|
||||
select(amox, nitr, fosf, trim, cipr) \%>\%
|
||||
ggplot_rsi(x = "Interpretation", facet = "Antibiotic")
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
\alias{portion_I}
|
||||
\alias{portion_SI}
|
||||
\alias{portion_S}
|
||||
\alias{portion_df}
|
||||
\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/}.
|
||||
@ -21,6 +22,8 @@ portion_I(ab1, minimum = 30, as_percent = FALSE)
|
||||
portion_SI(ab1, ab2 = NULL, minimum = 30, as_percent = FALSE)
|
||||
|
||||
portion_S(ab1, ab2 = NULL, minimum = 30, as_percent = FALSE)
|
||||
|
||||
portion_df(data, translate = getOption("get_antibiotic_names", TRUE))
|
||||
}
|
||||
\arguments{
|
||||
\item{ab1}{vector of antibiotic interpretations, they will be transformed internally with \code{\link{as.rsi}} if needed}
|
||||
@ -30,6 +33,10 @@ portion_S(ab1, ab2 = NULL, minimum = 30, as_percent = FALSE)
|
||||
\item{minimum}{minimal amount of available isolates. Any number lower than \code{minimum} will return \code{NA}. The default number of \code{30} isolates is advised by the CLSI as best practice, see Source.}
|
||||
|
||||
\item{as_percent}{logical to indicate whether the output must be returned as percent (text), will else be a double}
|
||||
|
||||
\item{data}{a code{data.frame} containing columns with class \code{rsi} (see \code{\link{as.rsi}})}
|
||||
|
||||
\item{translate}{a logical value to indicate whether antibiotic abbreviations should be translated with \code{\link{abname}}}
|
||||
}
|
||||
\value{
|
||||
Double or, when \code{as_percent = TRUE}, a character.
|
||||
@ -42,6 +49,8 @@ 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"}.
|
||||
|
||||
The old \code{\link{rsi}} function is still available for backwards compatibility but is deprecated.
|
||||
\if{html}{
|
||||
\cr\cr
|
||||
|
@ -5,9 +5,10 @@
|
||||
\alias{rsi_predict}
|
||||
\title{Predict antimicrobial resistance}
|
||||
\usage{
|
||||
resistance_predict(tbl, col_ab, col_date, year_min = NULL, year_max = NULL,
|
||||
year_every = 1, minimum = 30, model = "binomial", I_as_R = TRUE,
|
||||
preserve_measurements = TRUE, info = TRUE)
|
||||
resistance_predict(tbl, col_ab, col_date, year_min = NULL,
|
||||
year_max = NULL, year_every = 1, minimum = 30,
|
||||
model = "binomial", I_as_R = TRUE, preserve_measurements = TRUE,
|
||||
info = TRUE)
|
||||
|
||||
rsi_predict(tbl, col_ab, col_date, year_min = NULL, year_max = NULL,
|
||||
year_every = 1, minimum = 30, model = "binomial", I_as_R = TRUE,
|
||||
|
Reference in New Issue
Block a user