1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 18:06:11 +01:00
AMR/man/plot.Rd

222 lines
9.0 KiB
Plaintext
Raw Normal View History

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plotting.R
\name{plot}
\alias{plot}
\alias{scale_x_mic}
\alias{scale_y_mic}
\alias{scale_colour_mic}
\alias{scale_fill_mic}
\alias{plot.mic}
\alias{autoplot.mic}
2021-11-01 13:51:13 +01:00
\alias{fortify.mic}
\alias{plot.disk}
\alias{autoplot.disk}
2021-11-01 13:51:13 +01:00
\alias{fortify.disk}
2023-01-21 23:47:20 +01:00
\alias{plot.sir}
\alias{autoplot.sir}
\alias{fortify.sir}
\title{Plotting for Classes \code{sir}, \code{mic} and \code{disk}}
\usage{
2023-12-03 16:51:54 +01:00
scale_x_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
2023-12-03 16:51:54 +01:00
scale_y_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
2023-12-03 16:51:54 +01:00
scale_colour_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
2023-12-03 16:51:54 +01:00
scale_fill_mic(keep_operators = "edges", mic_range = NULL, drop = FALSE, ...)
\method{plot}{mic}(
2020-12-12 23:17:29 +01:00
x,
mo = NULL,
ab = NULL,
guideline = "EUCAST",
main = deparse(substitute(x)),
2023-03-11 14:24:34 +01:00
ylab = translate_AMR("Frequency", language = language),
xlab = translate_AMR("Minimum Inhibitory Concentration (mg/L)", language = language),
2023-01-21 23:47:20 +01:00
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
language = get_AMR_locale(),
expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...
)
2021-07-12 22:12:28 +02:00
\method{autoplot}{mic}(
2021-07-12 20:24:49 +02:00
object,
mo = NULL,
ab = NULL,
guideline = "EUCAST",
2022-08-19 12:33:14 +02:00
title = deparse(substitute(object)),
2023-03-11 14:24:34 +01:00
ylab = translate_AMR("Frequency", language = language),
xlab = translate_AMR("Minimum Inhibitory Concentration (mg/L)", language = language),
2023-01-21 23:47:20 +01:00
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
language = get_AMR_locale(),
expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...
)
2021-11-01 13:51:13 +01:00
\method{fortify}{mic}(object, ...)
\method{plot}{disk}(
x,
main = deparse(substitute(x)),
2023-03-11 14:24:34 +01:00
ylab = translate_AMR("Frequency", language = language),
xlab = translate_AMR("Disk diffusion diameter (mm)", language = language),
mo = NULL,
ab = NULL,
guideline = "EUCAST",
2023-01-21 23:47:20 +01:00
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
language = get_AMR_locale(),
expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...
)
2021-07-12 20:24:49 +02:00
\method{autoplot}{disk}(
object,
mo = NULL,
ab = NULL,
2022-08-19 12:33:14 +02:00
title = deparse(substitute(object)),
2023-03-11 14:24:34 +01:00
ylab = translate_AMR("Frequency", language = language),
xlab = translate_AMR("Disk diffusion diameter (mm)", language = language),
guideline = "EUCAST",
2023-01-21 23:47:20 +01:00
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
language = get_AMR_locale(),
expand = TRUE,
include_PKPD = getOption("AMR_include_PKPD", TRUE),
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
...
)
2021-11-01 13:51:13 +01:00
\method{fortify}{disk}(object, ...)
2023-01-21 23:47:20 +01:00
\method{plot}{sir}(
x,
2023-03-11 14:24:34 +01:00
ylab = translate_AMR("Percentage", language = language),
xlab = translate_AMR("Antimicrobial Interpretation", language = language),
main = deparse(substitute(x)),
2022-08-19 12:33:14 +02:00
language = get_AMR_locale(),
...
)
2021-02-26 12:11:29 +01:00
2023-01-21 23:47:20 +01:00
\method{autoplot}{sir}(
2021-07-12 20:24:49 +02:00
object,
2022-08-19 12:33:14 +02:00
title = deparse(substitute(object)),
2023-03-11 14:24:34 +01:00
xlab = translate_AMR("Antimicrobial Interpretation", language = language),
ylab = translate_AMR("Frequency", language = language),
2023-01-21 23:47:20 +01:00
colours_SIR = c("#3CAEA3", "#F6D55C", "#ED553B"),
language = get_AMR_locale(),
...
)
2021-11-01 13:51:13 +01:00
2023-01-21 23:47:20 +01:00
\method{fortify}{sir}(object, ...)
}
\arguments{
\item{keep_operators}{a \link{character} specifying how to handle operators (such as \code{>} and \code{<=}) in the input. Accepts one of three values: \code{"all"} (or \code{TRUE}) to keep all operators, \code{"none"} (or \code{FALSE}) to remove all operators, or \code{"edges"} to keep operators only at both ends of the range.}
\item{mic_range}{a manual range to limit the MIC values, e.g., \code{mic_range = c(0.001, 32)}. Use \code{NA} to set no limit on one side, e.g., \code{mic_range = c(NA, 32)}.}
2023-12-03 16:51:54 +01:00
\item{drop}{a \link{logical} to remove intermediate MIC values, defaults to \code{FALSE}}
\item{...}{arguments passed on to methods}
2023-01-21 23:47:20 +01:00
\item{x, object}{values created with \code{\link[=as.mic]{as.mic()}}, \code{\link[=as.disk]{as.disk()}} or \code{\link[=as.sir]{as.sir()}} (or their \verb{random_*} variants, such as \code{\link[=random_mic]{random_mic()}})}
\item{mo}{any (vector of) text that can be coerced to a valid microorganism code with \code{\link[=as.mo]{as.mo()}}}
2022-11-13 13:44:25 +01:00
\item{ab}{any (vector of) text that can be coerced to a valid antimicrobial drug code with \code{\link[=as.ab]{as.ab()}}}
\item{guideline}{interpretation guideline to use - the default is the latest included EUCAST guideline, see \emph{Details}}
2021-07-12 20:24:49 +02:00
\item{main, title}{title of the plot}
\item{xlab, ylab}{axis title}
2023-01-21 23:47:20 +01:00
\item{colours_SIR}{colours to use for filling in the bars, must be a vector of three values (in the order S, I and R). The default colours are colour-blind friendly.}
\item{language}{language to be used to translate 'Susceptible', 'Increased exposure'/'Intermediate' and 'Resistant' - the default is system language (see \code{\link[=get_AMR_locale]{get_AMR_locale()}}) and can be overwritten by setting the package option \code{\link[=AMR-options]{AMR_locale}}, e.g. \code{options(AMR_locale = "de")}, see \link{translate}. Use \code{language = NULL} or \code{language = ""} to prevent translation.}
2021-05-12 18:15:03 +02:00
\item{expand}{a \link{logical} to indicate whether the range on the x axis should be expanded between the lowest and highest value. For MIC values, intermediate values will be factors of 2 starting from the highest MIC value. For disk diameters, the whole diameter range will be filled.}
\item{include_PKPD}{a \link{logical} to indicate that PK/PD clinical breakpoints must be applied as a last resort - the default is \code{TRUE}. Can also be set with the package option \code{\link[=AMR-options]{AMR_include_PKPD}}.}
\item{breakpoint_type}{the type of breakpoints to use, either "ECOFF", "animal", or "human". ECOFF stands for Epidemiological Cut-Off values. The default is \code{"human"}, which can also be set with the package option \code{\link[=AMR-options]{AMR_breakpoint_type}}. If \code{host} is set to values of veterinary species, this will automatically be set to \code{"animal"}.}
}
\value{
2021-07-12 20:24:49 +02:00
The \code{autoplot()} functions return a \code{\link[ggplot2:ggplot]{ggplot}} model that is extendible with any \code{ggplot2} function.
2021-11-01 13:51:13 +01:00
The \code{fortify()} functions return a \link{data.frame} as an extension for usage in the \code{\link[ggplot2:ggplot]{ggplot2::ggplot()}} function.
}
\description{
2023-01-21 23:47:20 +01:00
Functions to plot classes \code{sir}, \code{mic} and \code{disk}, with support for base \R and \code{ggplot2}.
2023-12-03 01:06:00 +01:00
2023-12-04 08:19:02 +01:00
Especially the \verb{scale_*_mic()} functions are relevant wrappers to plot MIC values for \code{ggplot2}. They allows custom MIC ranges and to plot intermediate log2 levels for missing MIC values.
}
\details{
The interpretation of "I" will be named "Increased exposure" for all EUCAST guidelines since 2019, and will be named "Intermediate" in all other cases.
For interpreting MIC values as well as disk diffusion diameters, supported guidelines to be used as input for the \code{guideline} argument are: "EUCAST 2024", "EUCAST 2023", "EUCAST 2022", "EUCAST 2021", "EUCAST 2020", "EUCAST 2019", "EUCAST 2018", "EUCAST 2017", "EUCAST 2016", "EUCAST 2015", "EUCAST 2014", "EUCAST 2013", "EUCAST 2012", "EUCAST 2011", "CLSI 2024", "CLSI 2023", "CLSI 2022", "CLSI 2021", "CLSI 2020", "CLSI 2019", "CLSI 2018", "CLSI 2017", "CLSI 2016", "CLSI 2015", "CLSI 2014", "CLSI 2013", "CLSI 2012", and "CLSI 2011".
Simply using \code{"CLSI"} or \code{"EUCAST"} as input will automatically select the latest version of that guideline.
}
\examples{
some_mic_values <- random_mic(size = 100)
some_disk_values <- random_disk(size = 100, mo = "Escherichia coli", ab = "cipro")
2023-01-21 23:47:20 +01:00
some_sir_values <- random_sir(50, prob_SIR = c(0.55, 0.05, 0.30))
plot(some_mic_values)
plot(some_disk_values)
2023-01-21 23:47:20 +01:00
plot(some_sir_values)
# when providing the microorganism and antibiotic, colours will show interpretations:
plot(some_mic_values, mo = "S. aureus", ab = "ampicillin")
plot(some_disk_values, mo = "Escherichia coli", ab = "cipro")
2023-10-22 15:51:27 +02:00
plot(some_disk_values, mo = "Escherichia coli", ab = "cipro", language = "nl")
2023-12-03 01:06:00 +01:00
# Plotting using scale_x_mic()
\donttest{
if (require("ggplot2")) {
mic_plot <- ggplot(data.frame(mics = as.mic(c(0.25, "<=4", 4, 8, 32, ">=32")),
2023-12-03 01:06:00 +01:00
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")
2023-12-03 01:06:00 +01:00
}
if (require("ggplot2")) {
autoplot(some_mic_values)
}
if (require("ggplot2")) {
autoplot(some_disk_values, mo = "Escherichia coli", ab = "cipro")
}
if (require("ggplot2")) {
autoplot(some_sir_values)
}
2023-12-03 01:06:00 +01:00
}
2021-05-24 09:00:11 +02:00
}