1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-18 01:23:16 +02:00

(v2.1.1.9155) new mic_p50() and mic_p90() - updated AMR intro

This commit is contained in:
2025-02-23 11:18:08 +01:00
parent 226d10f546
commit aa8f6af185
24 changed files with 481 additions and 99 deletions

View File

@ -7,6 +7,8 @@
\alias{is.mic}
\alias{NA_mic_}
\alias{rescale_mic}
\alias{mic_p50}
\alias{mic_p90}
\alias{droplevels.mic}
\title{Transform Input to Minimum Inhibitory Concentrations (MIC)}
\usage{
@ -18,6 +20,10 @@ NA_mic_
rescale_mic(x, mic_range, keep_operators = "edges", as.mic = TRUE)
mic_p50(x, na.rm = FALSE, ...)
mic_p90(x, na.rm = FALSE, ...)
\method{droplevels}{mic}(x, as.mic = FALSE, ...)
}
\arguments{
@ -87,6 +93,8 @@ With \code{\link[=rescale_mic]{rescale_mic()}}, existing MIC ranges can be limit
For \code{ggplot2}, use one of the \code{\link[=scale_x_mic]{scale_*_mic()}} functions to plot MIC values. They allows custom MIC ranges and to plot intermediate log2 levels for missing MIC values.
\code{NA_mic_} is a missing value of the new \code{mic} class, analogous to e.g. base \R's \code{\link[base:NA]{NA_character_}}.
Use \code{\link[=mic_p50]{mic_p50()}} and \code{\link[=mic_p90]{mic_p90()}} to get the 50th and 90th percentile of MIC values. They return 'normal' \link{numeric} values.
}
\examples{
mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16"))

View File

@ -196,3 +196,128 @@ The interpretation of "I" will be named "Increased exposure" for all EUCAST guid
For interpreting MIC values as well as disk diffusion diameters, the default guideline is EUCAST 2024, unless the package option \code{\link[=AMR-options]{AMR_guideline}} is set. See \code{\link[=as.sir]{as.sir()}} for more information.
}
}
\examples{
some_mic_values <- random_mic(size = 100)
some_disk_values <- random_disk(size = 100, mo = "Escherichia coli", ab = "cipro")
some_sir_values <- random_sir(50, prob_SIR = c(0.55, 0.05, 0.30))
\donttest{
# Plotting using ggplot2's autoplot() for MIC, disk, and SIR -----------
if (require("ggplot2")) {
autoplot(some_mic_values)
}
if (require("ggplot2")) {
# when providing the microorganism and antibiotic, colours will show interpretations:
autoplot(some_mic_values, mo = "Escherichia coli", ab = "cipro")
}
if (require("ggplot2")) {
# support for 20 languages, various guidelines, and many options
autoplot(some_disk_values, mo = "Escherichia coli", ab = "cipro",
guideline = "CLSI 2024", language = "no",
title = "Disk diffusion from the North")
}
# Plotting using scale_x_mic() -----------------------------------------
if (require("ggplot2")) {
mic_plot <- ggplot(data.frame(mics = as.mic(c(0.25, "<=4", 4, 8, 32, ">=32")),
counts = c(1, 1, 2, 2, 3, 3)),
aes(mics, counts)) +
geom_col()
mic_plot +
labs(title = "without scale_x_mic()")
}
if (require("ggplot2")) {
mic_plot +
scale_x_mic() +
labs(title = "with scale_x_mic()")
}
if (require("ggplot2")) {
mic_plot +
scale_x_mic(keep_operators = "all") +
labs(title = "with scale_x_mic() keeping all operators")
}
if (require("ggplot2")) {
mic_plot +
scale_x_mic(mic_range = c(1, 16)) +
labs(title = "with scale_x_mic() using a manual 'within' range")
}
if (require("ggplot2")) {
mic_plot +
scale_x_mic(mic_range = c(0.032, 256)) +
labs(title = "with scale_x_mic() using a manual 'outside' range")
}
# Plotting using scale_y_mic() -----------------------------------------
some_groups <- sample(LETTERS[1:5], 20, replace = TRUE)
if (require("ggplot2")) {
ggplot(data.frame(mic = some_mic_values,
group = some_groups),
aes(group, mic)) +
geom_boxplot() +
geom_violin(linetype = 2, colour = "grey", fill = NA) +
scale_y_mic()
}
if (require("ggplot2")) {
ggplot(data.frame(mic = some_mic_values,
group = some_groups),
aes(group, mic)) +
geom_boxplot() +
geom_violin(linetype = 2, colour = "grey", fill = NA) +
scale_y_mic(mic_range = c(NA, 0.25))
}
# Plotting using scale_x_sir() -----------------------------------------
if (require("ggplot2")) {
ggplot(data.frame(x = c("I", "R", "S"),
y = c(45,323, 573)),
aes(x, y)) +
geom_col() +
scale_x_sir()
}
# Plotting using scale_y_mic() and scale_colour_sir() ------------------
if (require("ggplot2")) {
plain <- ggplot(data.frame(mic = some_mic_values,
group = some_groups,
sir = as.sir(some_mic_values,
mo = "E. coli",
ab = "cipro")),
aes(x = group, y = mic, colour = sir)) +
theme_minimal() +
geom_boxplot(fill = NA, colour = "grey") +
geom_jitter(width = 0.25)
plain
}
if (require("ggplot2")) {
# and now with our MIC and SIR scale functions:
plain +
scale_y_mic() +
scale_colour_sir()
}
if (require("ggplot2")) {
plain +
scale_y_mic(mic_range = c(0.005, 32), name = "Our MICs!") +
scale_colour_sir(language = "pt",
name = "Support in 20 languages")
}
}
# Plotting using base R's plot() ---------------------------------------
plot(some_mic_values)
# when providing the microorganism and antibiotic, colours will show interpretations:
plot(some_mic_values, mo = "S. aureus", ab = "ampicillin")
plot(some_disk_values)
plot(some_disk_values, mo = "Escherichia coli", ab = "cipro")
plot(some_disk_values, mo = "Escherichia coli", ab = "cipro", language = "nl")
plot(some_sir_values)
}