mirror of
https://github.com/msberends/AMR.git
synced 2026-11-15 22:20:47 +01:00
(v3.0.1.9151) Fix inconsistencies in the plotting functions and correct the translations of the interpretation categories
Plotting: - Base colours and legends of interpreted MIC and disk values on the interpretation itself instead of matching colours - Fix SDD in autoplot() for disks, the colours of barplot() for SIR values, and barplot() for MICs ignoring language and expand - Match a named colours_SIR by name; let keep_operators = TRUE/FALSE in scale_*_mic() behave as "all"/"none" - Let a named values in scale_*_sir() replace the colours it names, warn in scale_x_sir(), and pass other arguments on - Let the default of eucast_I follow the guideline option, also for EUCAST before 2019 - Support unquoted column names in facet_sir() without evaluating them - Correct the documentation and examples Translations: - Add SDD, NS, WT and NWT, and correct S, I, R and NI in 18 languages - Sources of the terms for 'I': NAK via German laboratories (de), SZU national reference laboratory (cs), lex.dk (da), Karolinska University Hospital (sv), COESANT (es), Nordlab (fi), CA-SFM (fr); no by analogy with da and sv - Not verified against an official source: ar, bn, el, hi, id, ja, ko, pl, ro, ru, sw, tr, uk, ur, vi, zh Tests: - Let the grouped antibiogram test use English so it passes in other locales
This commit is contained in:
1 parent
b63263cc56
commit
43accd35d1
9 files changed
+333
-359
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
Package: AMR
|
||||
Version: 3.0.1.9150
|
||||
Version: 3.0.1.9151
|
||||
Date: 2026-10-15
|
||||
Title: Antimicrobial Resistance Data Analysis
|
||||
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# AMR 3.0.1.9150
|
||||
# AMR 3.0.1.9151
|
||||
|
||||
Planned as v3.1.0, mid October 2026.
|
||||
|
||||
@@ -129,6 +129,19 @@ Planned as v3.1.0, mid October 2026.
|
||||
* New argument `round_to_next_log2` in `as.mic()` and `rescale_mic()` to round values up to the nearest log2 dilution level (#255)
|
||||
* `as.mic()` now handles values in scientific notation (e.g., `1e-3`) correctly
|
||||
* Input validation of `as.disk()` is now more strict, rejecting values that are not recognisable as a numeric disk zone diameter. Values higher than 50 mm now return `NA` with a warning, instead of being set to 50 mm.
|
||||
* Plotting (`plot()`, `barplot()`, and `autoplot()` for MIC, disk diffusion and SIR values, and the `scale_*_mic()` and `scale_*_sir()` functions)
|
||||
* The colours and legend labels of interpreted MIC and disk values are now based on the interpretation itself instead of matching colours, so that the legend of `plot()` no longer shows SDD when `colours_SIR` gives SDD the colour of S (e.g., with one or three colours), and NI and NS are labelled too
|
||||
* Fixed `autoplot()` for disk diffusion values, which left SDD bars without colour and legend entry
|
||||
* Fixed `barplot()` for MIC values, which ignored the `language` and `expand` arguments, and which now also has the `include_PKPD` and `breakpoint_type` arguments
|
||||
* Fixed `barplot()` for SIR values, which gave NI, WT, and NWT the wrong colours, and always showed empty bars for WT, NWT, and NS. `barplot()` and `autoplot()` for SIR values now always show S and R, and all other values (such as SDD, I, WT, NWT, and NS) only when they occur. Data with only WT and NWT shows these two.
|
||||
* `autoplot()` for disk diffusion values now validates `include_PKPD` and `breakpoint_type`, and `plot()` and `autoplot()` for SIR values now validate `language`
|
||||
* The y axis of `plot()` and `barplot()` now has a readable number of tick marks for large counts, instead of one per count
|
||||
* A named `colours_SIR` is now matched by name in all plotting functions, and needs at least the names S, I and R. SDD gets the colour of S if not set. Previously, the colours of S/I and I/R were taken by position, and a named vector of three colours gave missing colours.
|
||||
* `keep_operators = TRUE` and `FALSE` in the `scale_*_mic()` functions now behave like `"all"` and `"none"`, as in `as.mic()`
|
||||
* Fixed the `scale_*_sir()` functions failing when `values` was set. A named `values` (e.g., `values = c(S = "green")`) now replaces the colours of the SIR values it names, and `scale_x_sir()` warns that it ignores `values`.
|
||||
* Fixed `scale_x_sir()` ignoring other arguments, such as `name`
|
||||
* The `scale_*_sir()` functions now call 'I' "Intermediate" by default if the `AMR_guideline` option is set to EUCAST before 2019
|
||||
* `facet_sir()` now accepts unquoted column names, e.g., `facet_sir(antibiotic)`
|
||||
* MDRO determination (`mdro()`)
|
||||
* Resistance can now be inferred from a drug/inhibitor combination when the column of the base drug is absent (e.g., piperacillin inferred from piperacillin/tazobactam). This is controlled with the new argument `infer_from_combinations` (default: `TRUE`) (#209).
|
||||
* BRMO classification now includes bacterial complexes (#275)
|
||||
@@ -142,6 +155,8 @@ Planned as v3.1.0, mid October 2026.
|
||||
* Translating is now around 50 times faster, with identical results, as the translations are prepared once per language and applied to all values at once. This also makes `ab_group()` faster in other languages.
|
||||
* Translations are no longer translated again (e.g., "Ticarcillinee" in Dutch and "groupee" in French), and parts of combination names are no longer left untranslated
|
||||
* Fixed Italian names of CoNS and CoPS (#256), Dutch names of antimicrobials, and output of `sir_df()` in other languages (#272)
|
||||
* Added translations of "Susceptible dose-dependent", "Non-susceptible", "Wildtype", and "Non-wildtype", which were previously shown half translated in plots
|
||||
* Corrected the translations of the interpretation categories (S, I, R, and NI) in 18 languages, which were partly incorrect (e.g., Ukrainian words in Russian, "temporary" for Intermediate in Finnish, and "intermediate product" in Czech), and made them consistent with the newly added categories. Where available, the terms of national antimicrobial susceptibility testing committees and laboratories are used, e.g., "Sensibel bei erhöhter Exposition" (German), "Sensible, cuando se incrementa la exposición" (Spanish), and "Känslig vid ökad exponering" (Swedish).
|
||||
* Interpretive rules (`interpretive_rules()`, `eucast_rules()`, and `clsi_rules()`)
|
||||
* Considerably faster, around 11 to 18 times, with identical results
|
||||
* The number of added and changed values now only counts values that were actually written, so that values left untouched due to `overwrite = FALSE` or `add_if_missing = FALSE` are no longer reported as changes or additions, also not in the output of `verbose = TRUE` (#259)
|
||||
@@ -158,6 +173,7 @@ Planned as v3.1.0, mid October 2026.
|
||||
* Improved console messages with clickable links throughout the package, powered by `cli` if it is installed (#191, #265)
|
||||
* The section *Interpretation of SIR* (in `?as.sir`) now explains for all functions with a `guideline` argument for aggregated analyses how S, SDD, I, R, WT, NWT, NS, and NI are categorised per guideline. The handling of 'I' per MDRO guideline in `mdro()` will be revised in a future version (#323).
|
||||
* `labels_sir_count()` is now documented together with `ggplot_sir()`
|
||||
* Corrected the documentation of `colours_SIR` and `eucast_I` in the plotting functions, and an example of `scale_colour_sir()` in which the title was not applied
|
||||
* The documentation of `get_AMR_locale()` now describes the actual order in which the language is determined: the `AMR_locale` option, then the `LANG` system variable, then `LANGUAGE` only if `LANG` is not set, and then the system locale
|
||||
* Revamped console output of `interpretive_rules()`, with section headers, S/I/R values styled as in the printing of `sir` columns in tibbles, and the summary of edits sorted by SIR level, using `cli` if it is installed (#259)
|
||||
* The printing of `custom_interpretive_rules()` and `custom_mdro_guideline()` now styles SIR values as in tibbles, i.e., the colour of `I` depends on the guideline. `WT`, `NWT`, and `NS` were previously shown as `SDD`, `I`, and `R`, and values other than `S` and `R` as `I`.
|
||||
|
||||
@@ -138,6 +138,7 @@ TAXONOMY_VERSION <- list(
|
||||
|
||||
globalVariables(c(
|
||||
".coverage",
|
||||
".data",
|
||||
".GenericCallEnv",
|
||||
".lower",
|
||||
".mo",
|
||||
|
||||
+200
-335
@@ -32,18 +32,18 @@
|
||||
#' @description
|
||||
#' Functions to plot classes `sir`, `mic` and `disk`, with support for base \R and `ggplot2`.
|
||||
#'
|
||||
#' Especially the `scale_*_mic()` functions are relevant wrappers to plot MIC values for `ggplot2`. They allows custom MIC ranges and to plot intermediate log2 levels for missing MIC values.
|
||||
#' Especially the `scale_*_mic()` functions are relevant wrappers to plot MIC values for `ggplot2`. They allow custom MIC ranges and to plot intermediate log2 levels for missing MIC values.
|
||||
#' @param x,object Values created with [as.mic()], [as.disk()] or [as.sir()] (or their `random_*` variants, such as [random_mic()]).
|
||||
#' @param mo Any (vector of) text that can be coerced to a valid microorganism code with [as.mo()].
|
||||
#' @param ab Any (vector of) text that can be coerced to a valid antimicrobial drug code with [as.ab()].
|
||||
#' @param guideline Interpretation guideline to use - the default is the latest included EUCAST guideline, see *Details*.
|
||||
#' @param main,title Title of the plot.
|
||||
#' @param xlab,ylab Axis title.
|
||||
#' @param 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.
|
||||
#' @param colours_SIR Colours to use for filling in the bars, must be a vector of one, three or four values (in the order S, SDD, I and R), or a named vector with at least the names S, I and R. With three values or without a name SDD, SDD gets the colour of S. The default colours are colour-blind friendly.
|
||||
#' @param language Language to be used to translate 'Susceptible', 'Increased exposure'/'Intermediate' and 'Resistant' - the default is system language (see [get_AMR_locale()]) and can be overwritten by setting the package option [`AMR_locale`][AMR-options], e.g. `options(AMR_locale = "de")`, see [translate]. Use `language = NULL` to prevent translation.
|
||||
#' @param expand A [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.
|
||||
#' @param aesthetics Aesthetics to apply the colours to - the default is "fill" but can also be (a combination of) "alpha", "colour", "fill", "linetype", "shape" or "size".
|
||||
#' @param eucast_I A [logical] to indicate whether the 'I' must be interpreted as "Susceptible, under increased exposure". Will be `TRUE` if the default [AMR interpretation guideline][as.sir()] is set to EUCAST (which is the default). With `FALSE`, it will be interpreted as "Intermediate".
|
||||
#' @param eucast_I A [logical] to indicate whether the 'I' must be interpreted as "Susceptible, under increased exposure". Will be `TRUE` if the default [AMR interpretation guideline][as.sir()] is set to EUCAST 2019 or later (which is the default). With `FALSE`, it will be interpreted as "Intermediate".
|
||||
#' @inheritParams as.sir
|
||||
#' @param mic_range A manual range to rescale the MIC values (using [rescale_mic()]), e.g., `mic_range = c(0.001, 32)`. Use `NA` to prevent rescaling on one side, e.g., `mic_range = c(NA, 32)`. **Note:** This rescales values but does not filter them - use the ggplot2 `limits` argument separately to exclude values from the plot.
|
||||
#' @inheritParams as.mic
|
||||
@@ -52,7 +52,7 @@
|
||||
#' @details
|
||||
#' ### The `scale_*_mic()` Functions
|
||||
#'
|
||||
#' The functions [scale_x_mic()], [scale_y_mic()], [scale_colour_mic()], and [scale_fill_mic()] functions allow to plot the [mic][as.mic()] class (MIC values) on a continuous, logarithmic scale.
|
||||
#' The functions [scale_x_mic()], [scale_y_mic()], [scale_colour_mic()], and [scale_fill_mic()] allow to plot the [mic][as.mic()] class (MIC values) on a continuous, logarithmic scale.
|
||||
#'
|
||||
#' There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class [mic][as.mic()].
|
||||
#'
|
||||
@@ -60,7 +60,7 @@
|
||||
#'
|
||||
#' ### The `scale_*_sir()` Functions
|
||||
#'
|
||||
#' The functions [scale_x_sir()], [scale_colour_sir()], and [scale_fill_sir()] functions allow to plot the [sir][as.sir()] class in the right order (`r paste(levels(NA_sir_), collapse = " < ")`).
|
||||
#' The functions [scale_x_sir()], [scale_colour_sir()], and [scale_fill_sir()] allow to plot the [sir][as.sir()] class in the right order (`r paste(levels(NA_sir_), collapse = " < ")`).
|
||||
#'
|
||||
#' There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class [sir][as.sir()].
|
||||
#'
|
||||
@@ -74,9 +74,9 @@
|
||||
#' * [scale_y_percent()] transforms the y axis to a 0 to 100% range using [ggplot2::scale_y_continuous()].
|
||||
#' * [scale_sir_colours()] allows to set colours to any aesthetic, even for `shape` or `linetype`.
|
||||
#' * [theme_sir()] is a [ggplot2 theme][ggplot2::theme()] with minimal distraction.
|
||||
#' * [labels_sir_count()] print datalabels on the bars with percentage and number of isolates, using [ggplot2::geom_text()].
|
||||
#' * [labels_sir_count()] prints data labels on the bars with percentage and number of isolates, using [ggplot2::geom_text()].
|
||||
#'
|
||||
#' The interpretation of "I" will be named "Increased exposure" for all EUCAST guidelines since 2019, and will be named "Intermediate" in all other cases.
|
||||
#' The interpretation of "I" will be named "Susceptible, incr. exp." (susceptible, 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, the default guideline is `r AMR::clinical_breakpoints$guideline[1]`, unless the package option [`AMR_guideline`][AMR-options] is set. See [as.sir()] for more information.
|
||||
#' @name plot
|
||||
@@ -102,7 +102,7 @@
|
||||
#' }
|
||||
#'
|
||||
#' if (require("ggplot2")) {
|
||||
#' # support for 27 languages, various guidelines, and many options
|
||||
#' # support for all languages in ?translate, various guidelines, and many options
|
||||
#' autoplot(some_disk_values,
|
||||
#' mo = "Escherichia coli", ab = "cipro",
|
||||
#' guideline = "CLSI", language = "no",
|
||||
@@ -199,8 +199,8 @@
|
||||
#' ) +
|
||||
#' theme_minimal() +
|
||||
#' geom_boxplot(fill = NA, colour = "grey30") +
|
||||
#' geom_jitter(width = 0.25)
|
||||
#' labs(title = "scale_y_mic()/scale_colour_sir() automatically applied")
|
||||
#' geom_jitter(width = 0.25) +
|
||||
#' labs(title = "scale_y_mic()/scale_colour_sir() automatically applied")
|
||||
#'
|
||||
#' mic_sir_plot
|
||||
#' }
|
||||
@@ -209,7 +209,7 @@
|
||||
#' scale_y_mic(mic_range = c(0.005, 32), name = "Our MICs!") +
|
||||
#' scale_colour_sir(
|
||||
#' language = "pt", # Portuguese
|
||||
#' name = "Support in 28 languages"
|
||||
#' name = "Support in many languages"
|
||||
#' )
|
||||
#' }
|
||||
#' }
|
||||
@@ -231,6 +231,11 @@ NULL
|
||||
scale_type.mic <- function(x) c("mic", "discrete")
|
||||
|
||||
create_scale_mic <- function(aest, keep_operators, mic_range = NULL, ...) {
|
||||
if (isTRUE(keep_operators)) {
|
||||
keep_operators <- "all"
|
||||
} else if (isFALSE(keep_operators)) {
|
||||
keep_operators <- "none"
|
||||
}
|
||||
ggplot_fn <- getExportedValue(paste0("scale_", aest, "_continuous"),
|
||||
ns = asNamespace("ggplot2")
|
||||
)
|
||||
@@ -416,26 +421,28 @@ scale_type.sir <- function(x) c("sir", "discrete")
|
||||
|
||||
create_scale_sir <- function(aesthetics, colours_SIR, language, eucast_I, ...) {
|
||||
args <- list(...)
|
||||
args[c("value", "labels", "limits")] <- NULL
|
||||
user_values <- args$values
|
||||
args[c("values", "labels", "limits")] <- NULL
|
||||
|
||||
colours_SIR <- expand_SIR_colours(colours_SIR, unname = FALSE)
|
||||
|
||||
if (identical(aesthetics, "x")) {
|
||||
if (!is.null(user_values)) {
|
||||
warning_("The argument {.arg values} is ignored in {.help [{.fun scale_x_sir}](AMR::scale_x_sir)}, as it sets no colours.")
|
||||
}
|
||||
ggplot_fn <- ggplot2::scale_x_discrete
|
||||
} else {
|
||||
ggplot_fn <- ggplot2::scale_discrete_manual
|
||||
args <- c(
|
||||
args,
|
||||
list(
|
||||
aesthetics = aesthetics,
|
||||
values = c(colours_SIR,
|
||||
NI = "grey30",
|
||||
WT = unname(colours_SIR[1]),
|
||||
NWT = unname(colours_SIR[4]),
|
||||
NS = unname(colours_SIR[4])
|
||||
)
|
||||
values <- c(plot_sir_colour_values(colours_SIR), colours_SIR[c("SI", "IR")])
|
||||
if (!is.null(user_values)) {
|
||||
# 'values' as in ggplot2 replaces the colours of the SIR values it names
|
||||
stop_ifnot(
|
||||
!is.null(names(user_values)) && all(names(user_values) %in% names(values)),
|
||||
"{.arg values} must be named with any of: ", vector_or(names(values), quotes = FALSE, sort = FALSE), ". Use {.arg colours_SIR} for unnamed colours."
|
||||
)
|
||||
)
|
||||
values[names(user_values)] <- user_values
|
||||
}
|
||||
args <- c(args, list(aesthetics = aesthetics, values = values))
|
||||
}
|
||||
scale <- do.call(ggplot_fn, args)
|
||||
|
||||
@@ -482,12 +489,12 @@ scale_x_sir <- function(colours_SIR = c(
|
||||
R = "#ED553B"
|
||||
),
|
||||
language = get_AMR_locale(),
|
||||
eucast_I = getOption("AMR_guideline", "EUCAST") %like% "EUCAST",
|
||||
eucast_I = plot_name_of_I(getOption("AMR_guideline", "EUCAST")) != "Intermediate",
|
||||
...) {
|
||||
meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3, 4))
|
||||
language <- validate_language(language)
|
||||
meet_criteria(eucast_I, allow_class = "logical", has_length = 1)
|
||||
create_scale_sir(aesthetics = "x", colours_SIR = colours_SIR, language = language, eucast_I = eucast_I)
|
||||
create_scale_sir(aesthetics = "x", colours_SIR = colours_SIR, language = language, eucast_I = eucast_I, ...)
|
||||
}
|
||||
|
||||
#' @rdname plot
|
||||
@@ -499,7 +506,7 @@ scale_colour_sir <- function(colours_SIR = c(
|
||||
R = "#ED553B"
|
||||
),
|
||||
language = get_AMR_locale(),
|
||||
eucast_I = getOption("AMR_guideline", "EUCAST") %like% "EUCAST",
|
||||
eucast_I = plot_name_of_I(getOption("AMR_guideline", "EUCAST")) != "Intermediate",
|
||||
...) {
|
||||
meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3, 4))
|
||||
language <- validate_language(language)
|
||||
@@ -528,7 +535,7 @@ scale_fill_sir <- function(colours_SIR = c(
|
||||
R = "#ED553B"
|
||||
),
|
||||
language = get_AMR_locale(),
|
||||
eucast_I = getOption("AMR_guideline", "EUCAST") %like% "EUCAST",
|
||||
eucast_I = plot_name_of_I(getOption("AMR_guideline", "EUCAST")) != "Intermediate",
|
||||
...) {
|
||||
meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3, 4))
|
||||
language <- validate_language(language)
|
||||
@@ -581,9 +588,6 @@ plot.mic <- function(x,
|
||||
main <- gsub(" +", " ", paste0(main, collapse = " "))
|
||||
colours_SIR <- expand_SIR_colours(colours_SIR)
|
||||
|
||||
# wildtype/Non-wildtype
|
||||
is_wt_nwt <- identical(breakpoint_type, "ECOFF")
|
||||
|
||||
x <- plotrange_as_table(x, expand = expand)
|
||||
cols_sub <- plot_colours_subtitle_guideline(
|
||||
x = x,
|
||||
@@ -598,58 +602,7 @@ plot.mic <- function(x,
|
||||
breakpoint_type = breakpoint_type,
|
||||
...
|
||||
)
|
||||
barplot(x,
|
||||
col = cols_sub$cols,
|
||||
main = main,
|
||||
ylim = c(0, max(x) * ifelse(any(colours_SIR %in% cols_sub$cols), 1.1, 1)),
|
||||
ylab = ylab,
|
||||
xlab = xlab,
|
||||
axes = FALSE
|
||||
)
|
||||
axis(2, seq(0, max(x)))
|
||||
if (!is.null(cols_sub$sub)) {
|
||||
mtext(side = 3, line = 0.5, adj = 0.5, cex = 0.75, cols_sub$sub)
|
||||
}
|
||||
|
||||
if (any(colours_SIR %in% cols_sub$cols)) {
|
||||
legend_txt <- character(0)
|
||||
legend_col <- character(0)
|
||||
if (!is_wt_nwt & any(cols_sub$cols == colours_SIR[1] & cols_sub$count > 0)) {
|
||||
legend_txt <- c(legend_txt, "(S) Susceptible")
|
||||
legend_col <- colours_SIR[1]
|
||||
}
|
||||
if (is_wt_nwt & any(cols_sub$cols == colours_SIR[1] & cols_sub$count > 0)) {
|
||||
legend_txt <- c(legend_txt, "(WT) Wildtype")
|
||||
legend_col <- colours_SIR[1]
|
||||
}
|
||||
if (any(cols_sub$cols == colours_SIR[2] & cols_sub$count > 0)) {
|
||||
legend_txt <- c(legend_txt, "(SDD) Susceptible dose-dependent")
|
||||
legend_col <- c(legend_col, colours_SIR[2])
|
||||
}
|
||||
if (any(cols_sub$cols == colours_SIR[3] & cols_sub$count > 0)) {
|
||||
legend_txt <- c(legend_txt, paste("(I)", plot_name_of_I(cols_sub$guideline)))
|
||||
legend_col <- c(legend_col, colours_SIR[3])
|
||||
}
|
||||
if (!is_wt_nwt & any(cols_sub$cols == colours_SIR[4] & cols_sub$count > 0)) {
|
||||
legend_txt <- c(legend_txt, "(R) Resistant")
|
||||
legend_col <- c(legend_col, colours_SIR[4])
|
||||
}
|
||||
if (is_wt_nwt & any(cols_sub$cols == colours_SIR[4] & cols_sub$count > 0)) {
|
||||
legend_txt <- c(legend_txt, "(NWT) Non-wildtype")
|
||||
legend_col <- c(legend_col, colours_SIR[4])
|
||||
}
|
||||
|
||||
legend("top",
|
||||
x.intersp = 0.5,
|
||||
legend = translate_into_language(legend_txt, language = language),
|
||||
fill = legend_col,
|
||||
horiz = TRUE,
|
||||
cex = 0.75,
|
||||
box.lwd = 0,
|
||||
box.col = "#FFFFFF55",
|
||||
bg = "#FFFFFF55"
|
||||
)
|
||||
}
|
||||
plot_base_sir_bars(x = x, cols_sub = cols_sub, colours_SIR = colours_SIR, language = language, main = main, ylab = ylab, xlab = xlab, reverse_legend = FALSE)
|
||||
}
|
||||
|
||||
#' @method barplot mic
|
||||
@@ -670,16 +623,20 @@ barplot.mic <- function(height,
|
||||
),
|
||||
language = get_AMR_locale(),
|
||||
expand = TRUE,
|
||||
include_PKPD = getOption("AMR_include_PKPD", TRUE),
|
||||
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
|
||||
...) {
|
||||
meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE)
|
||||
meet_criteria(ylab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(xlab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE)
|
||||
meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE)
|
||||
meet_criteria(guideline, allow_class = "character", has_length = 1)
|
||||
meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE)
|
||||
meet_criteria(ylab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(xlab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3, 4))
|
||||
language <- validate_language(language)
|
||||
meet_criteria(expand, allow_class = "logical", has_length = 1)
|
||||
meet_criteria(include_PKPD, allow_class = "logical", has_length = 1)
|
||||
meet_criteria(breakpoint_type, allow_class = "character", is_in = AMR::clinical_breakpoints$type, has_length = 1)
|
||||
|
||||
main <- gsub(" +", " ", paste0(main, collapse = " "))
|
||||
|
||||
@@ -687,13 +644,17 @@ barplot.mic <- function(height,
|
||||
|
||||
plot(
|
||||
x = height,
|
||||
main = main,
|
||||
ylab = ylab,
|
||||
xlab = xlab,
|
||||
mo = mo,
|
||||
ab = ab,
|
||||
guideline = guideline,
|
||||
main = main,
|
||||
ylab = ylab,
|
||||
xlab = xlab,
|
||||
colours_SIR = colours_SIR,
|
||||
language = language,
|
||||
expand = expand,
|
||||
include_PKPD = include_PKPD,
|
||||
breakpoint_type = breakpoint_type,
|
||||
...
|
||||
)
|
||||
}
|
||||
@@ -742,9 +703,6 @@ autoplot.mic <- function(object,
|
||||
|
||||
colours_SIR <- expand_SIR_colours(colours_SIR)
|
||||
|
||||
# wildtype/Non-wildtype
|
||||
is_wt_nwt <- identical(breakpoint_type, "ECOFF")
|
||||
|
||||
object <- as.mic(object) # make sure that currently implemented MIC levels are used
|
||||
x <- plotrange_as_table(object, expand = expand)
|
||||
cols_sub <- plot_colours_subtitle_guideline(
|
||||
@@ -760,58 +718,7 @@ autoplot.mic <- function(object,
|
||||
breakpoint_type = breakpoint_type,
|
||||
...
|
||||
)
|
||||
df <- as.data.frame(x, stringsAsFactors = TRUE)
|
||||
colnames(df) <- c("mic", "count")
|
||||
df$cols <- cols_sub$cols
|
||||
df$cols[df$cols == colours_SIR[1] & !is_wt_nwt] <- "(S) Susceptible"
|
||||
df$cols[df$cols == colours_SIR[1] & is_wt_nwt] <- "(WT) Wildtype"
|
||||
df$cols[df$cols == colours_SIR[2]] <- "(SDD) Susceptible dose-dependent"
|
||||
df$cols[df$cols == colours_SIR[3]] <- paste("(I)", plot_name_of_I(cols_sub$guideline))
|
||||
df$cols[df$cols == colours_SIR[4] & !is_wt_nwt] <- "(R) Resistant"
|
||||
df$cols[df$cols == colours_SIR[4] & is_wt_nwt] <- "(NWT) Non-wildtype"
|
||||
df$cols <- factor(translate_into_language(df$cols, language = language),
|
||||
levels = translate_into_language(
|
||||
c(
|
||||
"(S) Susceptible",
|
||||
"(SDD) Susceptible dose-dependent",
|
||||
paste("(I)", plot_name_of_I(cols_sub$guideline)),
|
||||
"(R) Resistant",
|
||||
"(WT) Wildtype",
|
||||
"(NWT) Non-wildtype"
|
||||
),
|
||||
language = language
|
||||
),
|
||||
ordered = TRUE
|
||||
)
|
||||
p <- ggplot2::ggplot(df)
|
||||
|
||||
if (any(colours_SIR %in% cols_sub$cols)) {
|
||||
vals <- c(
|
||||
"(S) Susceptible" = colours_SIR[1],
|
||||
"(SDD) Susceptible dose-dependent" = colours_SIR[2],
|
||||
"(I) Susceptible, incr. exp." = colours_SIR[3],
|
||||
"(I) Intermediate" = colours_SIR[3],
|
||||
"(R) Resistant" = colours_SIR[4],
|
||||
"(NI) Non-interpretable" = "grey30",
|
||||
"(WT) Wildtype" = colours_SIR[1],
|
||||
"(NWT) Non-wildtype" = colours_SIR[4]
|
||||
)
|
||||
names(vals) <- translate_into_language(names(vals), language = language)
|
||||
p <- p +
|
||||
ggplot2::geom_col(ggplot2::aes(x = mic, y = count, fill = cols)) +
|
||||
# limits = force is needed because of a ggplot2 >= 3.3.4 bug (#4511)
|
||||
ggplot2::scale_fill_manual(
|
||||
values = vals,
|
||||
name = NULL,
|
||||
limits = force
|
||||
)
|
||||
} else {
|
||||
p <- p +
|
||||
ggplot2::geom_col(ggplot2::aes(x = mic, y = count))
|
||||
}
|
||||
|
||||
p +
|
||||
ggplot2::labs(title = title, x = xlab, y = ylab, subtitle = cols_sub$sub)
|
||||
plot_ggplot_sir_bars(x = x, method = "mic", cols_sub = cols_sub, colours_SIR = colours_SIR, language = language, title = title, ylab = ylab, xlab = xlab)
|
||||
}
|
||||
|
||||
#' @method fortify mic
|
||||
@@ -849,12 +756,12 @@ plot.disk <- function(x,
|
||||
include_PKPD = getOption("AMR_include_PKPD", TRUE),
|
||||
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
|
||||
...) {
|
||||
meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE)
|
||||
meet_criteria(ylab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(xlab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE)
|
||||
meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE)
|
||||
meet_criteria(guideline, allow_class = "character", has_length = 1)
|
||||
meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE)
|
||||
meet_criteria(ylab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(xlab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3, 4))
|
||||
language <- validate_language(language)
|
||||
meet_criteria(expand, allow_class = "logical", has_length = 1)
|
||||
@@ -864,9 +771,6 @@ plot.disk <- function(x,
|
||||
main <- gsub(" +", " ", paste0(main, collapse = " "))
|
||||
colours_SIR <- expand_SIR_colours(colours_SIR)
|
||||
|
||||
# wildtype/Non-wildtype
|
||||
is_wt_nwt <- identical(breakpoint_type, "ECOFF")
|
||||
|
||||
x <- plotrange_as_table(x, expand = expand)
|
||||
cols_sub <- plot_colours_subtitle_guideline(
|
||||
x = x,
|
||||
@@ -881,58 +785,8 @@ plot.disk <- function(x,
|
||||
breakpoint_type = breakpoint_type,
|
||||
...
|
||||
)
|
||||
|
||||
barplot(x,
|
||||
col = cols_sub$cols,
|
||||
main = main,
|
||||
ylim = c(0, max(x) * ifelse(any(colours_SIR %in% cols_sub$cols), 1.1, 1)),
|
||||
ylab = ylab,
|
||||
xlab = xlab,
|
||||
axes = FALSE
|
||||
)
|
||||
axis(2, seq(0, max(x)))
|
||||
if (!is.null(cols_sub$sub)) {
|
||||
mtext(side = 3, line = 0.5, adj = 0.5, cex = 0.75, cols_sub$sub)
|
||||
}
|
||||
|
||||
if (any(colours_SIR %in% cols_sub$cols)) {
|
||||
legend_txt <- character(0)
|
||||
legend_col <- character(0)
|
||||
if (!is_wt_nwt & any(cols_sub$cols == colours_SIR[4] & cols_sub$count > 0)) {
|
||||
legend_txt <- "(R) Resistant"
|
||||
legend_col <- colours_SIR[4]
|
||||
}
|
||||
if (is_wt_nwt & any(cols_sub$cols == colours_SIR[4] & cols_sub$count > 0)) {
|
||||
legend_txt <- "(NWT) Non-wildtype"
|
||||
legend_col <- colours_SIR[4]
|
||||
}
|
||||
if (any(cols_sub$cols == colours_SIR[3] & cols_sub$count > 0)) {
|
||||
legend_txt <- c(legend_txt, paste("(I)", plot_name_of_I(cols_sub$guideline)))
|
||||
legend_col <- c(legend_col, colours_SIR[3])
|
||||
}
|
||||
if (any(cols_sub$cols == colours_SIR[2] & cols_sub$count > 0)) {
|
||||
legend_txt <- c(legend_txt, "(SDD) Susceptible dose-dependent")
|
||||
legend_col <- c(legend_col, colours_SIR[2])
|
||||
}
|
||||
if (!is_wt_nwt & any(cols_sub$cols == colours_SIR[1] & cols_sub$count > 0)) {
|
||||
legend_txt <- c(legend_txt, "(S) Susceptible")
|
||||
legend_col <- c(legend_col, colours_SIR[1])
|
||||
}
|
||||
if (is_wt_nwt & any(cols_sub$cols == colours_SIR[1] & cols_sub$count > 0)) {
|
||||
legend_txt <- c(legend_txt, "(WT) Wildtype")
|
||||
legend_col <- c(legend_col, colours_SIR[1])
|
||||
}
|
||||
legend("top",
|
||||
x.intersp = 0.5,
|
||||
legend = translate_into_language(legend_txt, language = language),
|
||||
fill = legend_col,
|
||||
horiz = TRUE,
|
||||
cex = 0.75,
|
||||
box.lwd = 0,
|
||||
box.col = "#FFFFFF55",
|
||||
bg = "#FFFFFF55"
|
||||
)
|
||||
}
|
||||
# zone diameters run from resistant to susceptible, so the legend does too
|
||||
plot_base_sir_bars(x = x, cols_sub = cols_sub, colours_SIR = colours_SIR, language = language, main = main, ylab = ylab, xlab = xlab, reverse_legend = TRUE)
|
||||
}
|
||||
|
||||
#' @method barplot disk
|
||||
@@ -956,12 +810,12 @@ barplot.disk <- function(height,
|
||||
include_PKPD = getOption("AMR_include_PKPD", TRUE),
|
||||
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
|
||||
...) {
|
||||
meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE)
|
||||
meet_criteria(ylab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(xlab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE)
|
||||
meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE)
|
||||
meet_criteria(guideline, allow_class = "character", has_length = 1)
|
||||
meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE)
|
||||
meet_criteria(ylab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(xlab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3, 4))
|
||||
language <- validate_language(language)
|
||||
meet_criteria(expand, allow_class = "logical", has_length = 1)
|
||||
@@ -972,12 +826,12 @@ barplot.disk <- function(height,
|
||||
|
||||
plot(
|
||||
x = height,
|
||||
main = main,
|
||||
ylab = ylab,
|
||||
xlab = xlab,
|
||||
mo = mo,
|
||||
ab = ab,
|
||||
guideline = guideline,
|
||||
main = main,
|
||||
ylab = ylab,
|
||||
xlab = xlab,
|
||||
colours_SIR = colours_SIR,
|
||||
language = language,
|
||||
expand = expand,
|
||||
@@ -1010,15 +864,17 @@ autoplot.disk <- function(object,
|
||||
breakpoint_type = getOption("AMR_breakpoint_type", "human"),
|
||||
...) {
|
||||
stop_ifnot_installed("ggplot2")
|
||||
meet_criteria(title, allow_class = "character", allow_NULL = TRUE)
|
||||
meet_criteria(ylab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(xlab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(mo, allow_class = c("mo", "character"), allow_NULL = TRUE)
|
||||
meet_criteria(ab, allow_class = c("ab", "character"), allow_NULL = TRUE)
|
||||
meet_criteria(guideline, allow_class = "character", has_length = 1)
|
||||
meet_criteria(title, allow_class = "character", allow_NULL = TRUE)
|
||||
meet_criteria(ylab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(xlab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3, 4))
|
||||
language <- validate_language(language)
|
||||
meet_criteria(expand, allow_class = "logical", has_length = 1)
|
||||
meet_criteria(include_PKPD, allow_class = "logical", has_length = 1)
|
||||
meet_criteria(breakpoint_type, allow_class = "character", is_in = AMR::clinical_breakpoints$type, has_length = 1)
|
||||
|
||||
if ("main" %in% names(list(...))) {
|
||||
title <- list(...)$main
|
||||
@@ -1029,9 +885,6 @@ autoplot.disk <- function(object,
|
||||
|
||||
colours_SIR <- expand_SIR_colours(colours_SIR)
|
||||
|
||||
# wildtype/Non-wildtype
|
||||
is_wt_nwt <- identical(breakpoint_type, "ECOFF")
|
||||
|
||||
x <- plotrange_as_table(object, expand = expand)
|
||||
cols_sub <- plot_colours_subtitle_guideline(
|
||||
x = x,
|
||||
@@ -1046,56 +899,7 @@ autoplot.disk <- function(object,
|
||||
breakpoint_type = breakpoint_type,
|
||||
...
|
||||
)
|
||||
df <- as.data.frame(x, stringsAsFactors = TRUE)
|
||||
colnames(df) <- c("disk", "count")
|
||||
df$cols <- cols_sub$cols
|
||||
df$cols[df$cols == colours_SIR[1] & !is_wt_nwt] <- "(S) Susceptible"
|
||||
df$cols[df$cols == colours_SIR[1] & is_wt_nwt] <- "(WT) Wildtype"
|
||||
df$cols[df$cols == colours_SIR[2]] <- "(SDD) Susceptible dose-dependent"
|
||||
df$cols[df$cols == colours_SIR[3]] <- paste("(I)", plot_name_of_I(cols_sub$guideline))
|
||||
df$cols[df$cols == colours_SIR[4] & !is_wt_nwt] <- "(R) Resistant"
|
||||
df$cols[df$cols == colours_SIR[4] & is_wt_nwt] <- "(NWT) Non-wildtype"
|
||||
df$cols <- factor(translate_into_language(df$cols, language = language),
|
||||
levels = translate_into_language(
|
||||
c(
|
||||
"(S) Susceptible",
|
||||
paste("(I)", plot_name_of_I(cols_sub$guideline)),
|
||||
"(R) Resistant",
|
||||
"(WT) Wildtype",
|
||||
"(NWT) Non-wildtype"
|
||||
),
|
||||
language = language
|
||||
),
|
||||
ordered = TRUE
|
||||
)
|
||||
p <- ggplot2::ggplot(df)
|
||||
if (any(colours_SIR %in% cols_sub$cols)) {
|
||||
vals <- c(
|
||||
"(S) Susceptible" = colours_SIR[1],
|
||||
"(SDD) Susceptible dose-dependent" = colours_SIR[2],
|
||||
"(I) Susceptible, incr. exp." = colours_SIR[3],
|
||||
"(I) Intermediate" = colours_SIR[3],
|
||||
"(R) Resistant" = colours_SIR[4],
|
||||
"(NI) Non-interpretable" = "grey30",
|
||||
"(WT) Wildtype" = colours_SIR[1],
|
||||
"(NWT) Non-wildtype" = colours_SIR[4]
|
||||
)
|
||||
names(vals) <- translate_into_language(names(vals), language = language)
|
||||
p <- p +
|
||||
ggplot2::geom_col(ggplot2::aes(x = disk, y = count, fill = cols)) +
|
||||
# limits = force is needed because of a ggplot2 >= 3.3.4 bug (#4511)
|
||||
ggplot2::scale_fill_manual(
|
||||
values = vals,
|
||||
name = NULL,
|
||||
limits = force
|
||||
)
|
||||
} else {
|
||||
p <- p +
|
||||
ggplot2::geom_col(ggplot2::aes(x = disk, y = count))
|
||||
}
|
||||
|
||||
p +
|
||||
ggplot2::labs(title = title, x = xlab, y = ylab, subtitle = cols_sub$sub)
|
||||
plot_ggplot_sir_bars(x = x, method = "disk", cols_sub = cols_sub, colours_SIR = colours_SIR, language = language, title = title, ylab = ylab, xlab = xlab)
|
||||
}
|
||||
|
||||
#' @method fortify disk
|
||||
@@ -1122,6 +926,7 @@ plot.sir <- function(x,
|
||||
meet_criteria(ylab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(xlab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(main, allow_class = "character", has_length = 1, allow_NULL = TRUE)
|
||||
language <- validate_language(language)
|
||||
|
||||
data <- as.data.frame(table(x), stringsAsFactors = FALSE)
|
||||
colnames(data) <- c("x", "n")
|
||||
@@ -1196,29 +1001,19 @@ barplot.sir <- function(height,
|
||||
meet_criteria(expand, allow_class = "logical", has_length = 1)
|
||||
|
||||
colours_SIR <- expand_SIR_colours(colours_SIR)
|
||||
|
||||
# add SDD and N to colours
|
||||
colours_SIR <- c(colours_SIR, "grey30")
|
||||
main <- gsub(" +", " ", paste0(main, collapse = " "))
|
||||
|
||||
x <- table(height)
|
||||
if (all(height %in% c("WT", "NWT"), na.rm = TRUE)) {
|
||||
colours_SIR <- colours_SIR[c(1, 4)]
|
||||
x <- x[names(x) %in% c("WT", "NWT")]
|
||||
} else {
|
||||
# remove missing I, SDD, and N
|
||||
colours_SIR <- colours_SIR[!(names(x) %in% c("SDD", "I", "NI") & x == 0)]
|
||||
x <- x[!(names(x) %in% c("SDD", "I", "NI") & x == 0)]
|
||||
}
|
||||
x <- x[plot_sir_levels_to_keep(height, x)]
|
||||
# plot it
|
||||
barplot(x,
|
||||
col = colours_SIR,
|
||||
col = unname(plot_sir_colour_values(colours_SIR)[names(x)]),
|
||||
xlab = xlab,
|
||||
main = main,
|
||||
ylab = ylab,
|
||||
axes = FALSE
|
||||
)
|
||||
axis(2, seq(0, max(x)))
|
||||
axis(2, plot_count_ticks(max(x)))
|
||||
}
|
||||
|
||||
#' @method autoplot sir
|
||||
@@ -1242,6 +1037,7 @@ autoplot.sir <- function(object,
|
||||
meet_criteria(ylab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(xlab, allow_class = "character", has_length = 1)
|
||||
meet_criteria(colours_SIR, allow_class = "character", has_length = c(1, 3, 4))
|
||||
language <- validate_language(language)
|
||||
|
||||
if ("main" %in% names(list(...))) {
|
||||
title <- list(...)$main
|
||||
@@ -1254,25 +1050,12 @@ autoplot.sir <- function(object,
|
||||
|
||||
df <- as.data.frame(table(object), stringsAsFactors = TRUE)
|
||||
colnames(df) <- c("x", "n")
|
||||
df <- df[!(df$n == 0 & df$x %in% c("SDD", "I", "NI")), , drop = FALSE]
|
||||
if (all(object %in% c("WT", "NWT"), na.rm = TRUE)) {
|
||||
df <- df[which(df$x %in% c("WT", "NWT")), ]
|
||||
} else {
|
||||
df <- df[which(!df$x %in% c("WT", "NWT", "NS")), ]
|
||||
}
|
||||
df <- df[plot_sir_levels_to_keep(object, stats::setNames(df$n, df$x)), , drop = FALSE]
|
||||
ggplot2::ggplot(df) +
|
||||
ggplot2::geom_col(ggplot2::aes(x = x, y = n, fill = x)) +
|
||||
# limits = force is needed because of a ggplot2 >= 3.3.4 bug (#4511)
|
||||
ggplot2::scale_fill_manual(
|
||||
values = c(
|
||||
"S" = colours_SIR[1],
|
||||
"SDD" = colours_SIR[2],
|
||||
"I" = colours_SIR[3],
|
||||
"R" = colours_SIR[4],
|
||||
"NI" = "grey30",
|
||||
"WT" = colours_SIR[1],
|
||||
"NWT" = colours_SIR[4]
|
||||
),
|
||||
values = plot_sir_colour_values(colours_SIR),
|
||||
limits = force
|
||||
) +
|
||||
ggplot2::labs(title = title, x = xlab, y = ylab) +
|
||||
@@ -1290,6 +1073,106 @@ fortify.sir <- function(object, ...) {
|
||||
)
|
||||
}
|
||||
|
||||
# colours for all values of VALID_SIR_LEVELS, named by level, based on the output of expand_SIR_colours() (in the order S, SDD, I, R, SI, IR)
|
||||
plot_sir_colour_values <- function(colours_SIR) {
|
||||
c(
|
||||
S = unname(colours_SIR[1]),
|
||||
SDD = unname(colours_SIR[2]),
|
||||
I = unname(colours_SIR[3]),
|
||||
R = unname(colours_SIR[4]),
|
||||
NI = "grey30",
|
||||
WT = unname(colours_SIR[1]),
|
||||
NWT = unname(colours_SIR[4]),
|
||||
NS = unname(colours_SIR[4])
|
||||
)
|
||||
}
|
||||
|
||||
# legend labels for all values of VALID_SIR_LEVELS, named by level
|
||||
plot_sir_label_values <- function(guideline) {
|
||||
c(
|
||||
S = "(S) Susceptible",
|
||||
SDD = "(SDD) Susceptible dose-dependent",
|
||||
I = paste("(I)", plot_name_of_I(guideline)),
|
||||
R = "(R) Resistant",
|
||||
NI = "(NI) Non-interpretable",
|
||||
WT = "(WT) Wildtype",
|
||||
NWT = "(NWT) Non-wildtype",
|
||||
NS = "(NS) Non-susceptible"
|
||||
)
|
||||
}
|
||||
|
||||
# for bar plots of SIR values: keep S and R, and other levels only if they occur; keep only WT and NWT if the data contains nothing else
|
||||
plot_sir_levels_to_keep <- function(values, counts) {
|
||||
values <- as.character(values[!is.na(values)])
|
||||
if (length(values) > 0 && all(values %in% c("WT", "NWT"))) {
|
||||
names(counts) %in% c("WT", "NWT")
|
||||
} else {
|
||||
names(counts) %in% c("S", "R") | counts > 0
|
||||
}
|
||||
}
|
||||
|
||||
# integer tick marks for an axis with counts, around 5 ticks as with pretty()
|
||||
plot_count_ticks <- function(max_count) {
|
||||
ticks <- pretty(c(0, max_count))
|
||||
ticks[ticks == round(ticks)]
|
||||
}
|
||||
|
||||
plot_base_sir_bars <- function(x, cols_sub, colours_SIR, language, main, ylab, xlab, reverse_legend) {
|
||||
# SIR values that occur in the data, in the order of VALID_SIR_LEVELS
|
||||
in_legend <- VALID_SIR_LEVELS[VALID_SIR_LEVELS %in% as.character(cols_sub$sir[cols_sub$count > 0])]
|
||||
if (isTRUE(reverse_legend)) {
|
||||
in_legend <- rev(in_legend)
|
||||
}
|
||||
barplot(x,
|
||||
col = cols_sub$cols,
|
||||
main = main,
|
||||
ylim = c(0, max(x) * ifelse(length(in_legend) > 0, 1.1, 1)),
|
||||
ylab = ylab,
|
||||
xlab = xlab,
|
||||
axes = FALSE
|
||||
)
|
||||
axis(2, plot_count_ticks(max(x)))
|
||||
if (!is.null(cols_sub$sub)) {
|
||||
mtext(side = 3, line = 0.5, adj = 0.5, cex = 0.75, cols_sub$sub)
|
||||
}
|
||||
if (length(in_legend) > 0) {
|
||||
legend("top",
|
||||
x.intersp = 0.5,
|
||||
legend = translate_into_language(unname(plot_sir_label_values(cols_sub$guideline)[in_legend]), language = language),
|
||||
fill = unname(plot_sir_colour_values(colours_SIR)[in_legend]),
|
||||
horiz = TRUE,
|
||||
cex = 0.75,
|
||||
box.lwd = 0,
|
||||
box.col = "#FFFFFF55",
|
||||
bg = "#FFFFFF55"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
plot_ggplot_sir_bars <- function(x, method, cols_sub, colours_SIR, language, title, ylab, xlab) {
|
||||
df <- as.data.frame(x, stringsAsFactors = TRUE)
|
||||
colnames(df) <- c(method, "count")
|
||||
if (any(!is.na(cols_sub$sir))) {
|
||||
labels <- plot_sir_label_values(cols_sub$guideline)
|
||||
labels[] <- translate_into_language(labels, language = language)
|
||||
df$cols <- factor(unname(labels[as.character(cols_sub$sir)]), levels = unname(labels), ordered = TRUE)
|
||||
p <- ggplot2::ggplot(df) +
|
||||
ggplot2::geom_col(ggplot2::aes(x = .data[[method]], y = count, fill = cols)) +
|
||||
# limits = force is needed because of a ggplot2 >= 3.3.4 bug (#4511)
|
||||
ggplot2::scale_fill_manual(
|
||||
values = stats::setNames(unname(plot_sir_colour_values(colours_SIR)[names(labels)]), labels),
|
||||
name = NULL,
|
||||
limits = force,
|
||||
na.value = "#BEBEBE"
|
||||
)
|
||||
} else {
|
||||
p <- ggplot2::ggplot(df) +
|
||||
ggplot2::geom_col(ggplot2::aes(x = .data[[method]], y = count))
|
||||
}
|
||||
p +
|
||||
ggplot2::labs(title = title, x = xlab, y = ylab, subtitle = cols_sub$sub)
|
||||
}
|
||||
|
||||
plotrange_as_table <- function(x, expand, keep_operators = "all", mic_range = NULL) {
|
||||
x <- x[!is.na(x)]
|
||||
if (is.mic(x)) {
|
||||
@@ -1332,17 +1215,10 @@ plotrange_as_table <- function(x, expand, keep_operators = "all", mic_range = NU
|
||||
as.table(x)
|
||||
}
|
||||
|
||||
ggplot2_get_from_dots <- function(arg, default, ...) {
|
||||
dots <- list(...)
|
||||
if (!arg %in% names(dots)) {
|
||||
default
|
||||
} else {
|
||||
dots[[arg]]
|
||||
}
|
||||
}
|
||||
|
||||
plot_name_of_I <- function(guideline) {
|
||||
if (guideline %unlike% "CLSI" && as.double(gsub("[^0-9]+", "", guideline)) >= 2019) {
|
||||
# a guideline without a year, such as "EUCAST", is the latest version
|
||||
year <- suppressWarnings(as.double(gsub("[^0-9]+", "", guideline)))
|
||||
if (guideline %unlike% "CLSI" && (is.na(year) || year >= 2019)) {
|
||||
# interpretation since 2019
|
||||
"Susceptible, incr. exp."
|
||||
} else {
|
||||
@@ -1393,18 +1269,12 @@ plot_colours_subtitle_guideline <- function(x, mo, ab, guideline, colours_SIR, f
|
||||
ref_tbl <- paste0('"', unique(AMR_env$sir_interpretation_history$ref_table), '"', collapse = "/")
|
||||
guideline_txt <- paste0("(", guideline_txt, ": ", ref_tbl, ")")
|
||||
}
|
||||
cols <- character(length = length(sir))
|
||||
cols[is.na(sir)] <- "#BEBEBE"
|
||||
cols[sir == "S"] <- colours_SIR[1]
|
||||
cols[sir == "SDD"] <- colours_SIR[2]
|
||||
cols[sir == "I"] <- colours_SIR[3]
|
||||
cols[sir == "R"] <- colours_SIR[4]
|
||||
cols[sir == "NI"] <- "grey30"
|
||||
cols[sir == "WT"] <- colours_SIR[1]
|
||||
cols[sir == "NWT"] <- colours_SIR[4]
|
||||
cols[sir == "NS"] <- colours_SIR[4]
|
||||
sir <- as.character(sir)
|
||||
cols <- unname(plot_sir_colour_values(colours_SIR)[sir])
|
||||
cols[is.na(cols)] <- "#BEBEBE"
|
||||
sub <- bquote(.(abname) ~ "-" ~ italic(.(moname)) ~ .(guideline_txt))
|
||||
} else {
|
||||
sir <- rep(NA_character_, length(x))
|
||||
cols <- "#BEBEBE"
|
||||
sub <- NULL
|
||||
}
|
||||
@@ -1412,28 +1282,24 @@ plot_colours_subtitle_guideline <- function(x, mo, ab, guideline, colours_SIR, f
|
||||
# restore previous interpretations to backup
|
||||
AMR_env$sir_interpretation_history <- sir_history
|
||||
|
||||
list(cols = cols, count = as.double(x), sub = sub, guideline = guideline)
|
||||
list(cols = cols, sir = sir, count = as.double(x), sub = sub, guideline = guideline)
|
||||
}
|
||||
|
||||
#' @rdname plot
|
||||
#' @export
|
||||
facet_sir <- function(facet = c("interpretation", "antibiotic"), nrow = NULL) {
|
||||
# support unquoted column names, such as facet_sir(antibiotic), without evaluating them
|
||||
if (!missing(facet) && is.symbol(substitute(facet))) {
|
||||
facet <- as.character(substitute(facet))
|
||||
}
|
||||
facet <- facet[1]
|
||||
stop_ifnot_installed("ggplot2")
|
||||
meet_criteria(facet, allow_class = "character", has_length = 1)
|
||||
meet_criteria(nrow, allow_class = c("numeric", "integer"), has_length = 1, allow_NULL = TRUE, is_positive = TRUE, is_finite = TRUE)
|
||||
|
||||
facet_deparse <- deparse(substitute(facet))
|
||||
if (facet_deparse != "facet") {
|
||||
facet <- facet_deparse
|
||||
}
|
||||
if (facet %like% '".*"') {
|
||||
facet <- substr(facet, 2, nchar(facet) - 1)
|
||||
}
|
||||
|
||||
if (tolower(facet) %in% tolower(c("SIR", "sir", "interpretations", "result"))) {
|
||||
if (tolower(facet) %in% c("sir", "interpretations", "result")) {
|
||||
facet <- "interpretation"
|
||||
} else if (tolower(facet) %in% tolower(c("ab", "abx", "antimicrobials"))) {
|
||||
} else if (tolower(facet) %in% c("ab", "abx", "antimicrobials")) {
|
||||
facet <- "antibiotic"
|
||||
}
|
||||
|
||||
@@ -1608,26 +1474,25 @@ expand_SIR_colours <- function(colours_SIR, unname = TRUE) {
|
||||
colours_SIR <- rep(colours_SIR, 4)
|
||||
} else if (length(colours_SIR) == 3) {
|
||||
# old method for AMR < 3.0.1 which allowed for 3 colours
|
||||
# fill in green for SDD as extra colour
|
||||
# fill in the colour of S for SDD
|
||||
colours_SIR <- c(colours_SIR[1], colours_SIR[1], colours_SIR[2], colours_SIR[3])
|
||||
}
|
||||
if (length(colours_SIR) == 4) {
|
||||
# add colours for SI (same as S) and IR (same as R)
|
||||
colours_SIR <- c(colours_SIR[1:4], colours_SIR[1], colours_SIR[4])
|
||||
}
|
||||
names(colours_SIR) <- sir_order
|
||||
names(colours_SIR) <- sir_order[1:4]
|
||||
} else {
|
||||
# named input: match and reorder
|
||||
# named input: match by name
|
||||
stop_ifnot(
|
||||
all(names(colours_SIR) %in% sir_order),
|
||||
"Unknown names in {.arg colours_SIR}. Expected any of: ", vector_or(levels(NA_sir_), quotes = FALSE, sort = FALSE), "."
|
||||
"Unknown names in {.arg colours_SIR}. Expected any of: ", vector_or(sir_order, quotes = FALSE, sort = FALSE), "."
|
||||
)
|
||||
stop_ifnot(
|
||||
all(c("S", "I", "R") %in% names(colours_SIR)),
|
||||
"A named {.arg colours_SIR} must contain at least the names S, I and R."
|
||||
)
|
||||
if (length(colours_SIR) == 4) {
|
||||
# add colours for SI (same as S) and IR (same as R)
|
||||
colours_SIR <- c(colours_SIR[1:4], SI = unname(colours_SIR[1]), IR = unname(colours_SIR[4]))
|
||||
}
|
||||
colours_SIR <- colours_SIR[sir_order]
|
||||
}
|
||||
# SDD and SI get the colour of S, and IR gets the colour of R, unless set
|
||||
colours_SIR[setdiff(c("SDD", "SI"), names(colours_SIR))] <- colours_SIR[["S"]]
|
||||
colours_SIR[setdiff("IR", names(colours_SIR))] <- colours_SIR[["R"]]
|
||||
colours_SIR <- colours_SIR[sir_order]
|
||||
|
||||
if (unname) {
|
||||
colours_SIR <- unname(colours_SIR)
|
||||
|
||||
Binary file not shown.
@@ -39,13 +39,17 @@ vegetative TRUE TRUE FALSE FALSE vegetative نباتي/خضري উদ্ভি
|
||||
([([ ]*?)Group\\b TRUE TRUE FALSE FALSE \\1Group \\1 مجموعة \\1গ্রুপ ([([]*?)组 \\1Skupina \\1Gruppe \\1Groep \\1Ryhmä \\1Groupe \\1Gruppe ([([ ]*;)ομάδα \\1समूह \\1Grup \\1Gruppo \\1グループ \\1그룹 \\1Gruppe ([([ ]*?)Grupa \\1Grupo \\1Grup \\1Группа \\1Grupo \\1 Kundi \\1Grupp ([([ ]*?)Grup \\1Група \\1گروپ \\1Nhóm
|
||||
no .*growth FALSE FALSE FALSE FALSE no .*growth لا يوجد نمو কোনও বৃদ্ধি নেই 无.*生长 žádný .*růst ingen .*vækst geen .*groei ei .*kasvua pas .*croissance keine(|n|m|r|s)|nicht .*wachstum όχι .*αύξηση कोई वृद्धि नहीं Tidak ada pertumbuhan sem .*crescimento 成長なし 성장 없음 nei .*vekst brak .*wzrostu sem .*crescimento fără creștere отсутствие.*роста no .*crecimientonon Hakuna ukuaji ingen .*tillväxt büyüme yok відсутність .*росту کسی قسم کی افزائش نہیں Không có phát triển
|
||||
no|not FALSE FALSE FALSE FALSE no|not لا না|নয় 不|不 ne nej|ikke geen|niet ei non keine? no|not नहीं tidak|bukan sem no|ない 없음 nei|ikke nie|nie sem nu нет? no|sin hapana nej|inte hayır|değil|hayir|degil ні نہیں|نہ không
|
||||
Intermediate TRUE FALSE FALSE FALSE Intermediate متوسط মধ্যবর্তী 中级 Meziprodukt Mellemliggende Intermediair Väliaikainen Intermédiaire Mittlere Ενδιάμεση मध्यम Intermediat Intermedio 中間体 중간 Mellomliggende Pośrednia Intermediário Intermediar Проміжний Intermedio Kati Mellanliggande Orta seviye Знижена чутливість درمیانی Trung gian
|
||||
Susceptible, incr. exp. FALSE TRUE FALSE FALSE Susceptible, incr. exp. حساس، يحتاج تعرض زائد সংবেদনশীল, অতিরিক্ত এক্সপোজার প্রয়োজন 易感,暴露增加 Vnímavý, zvýšená expozice Modtagelig, øget eksponering Gevoelig bij verhoogde blootstelling Altis, lisääntynyt altistuminen Sensible, à forte posologie Empfindlich, erhöhte Belastung Ευάλωτος, αυξημένη έκθεση संवेदनशील, अधिक संपर्क Rentan, perlu paparan tambahan Sensibile, esposizione aumentata 感受性、曝露量増加 감수성, 노출 증가 필요 Mottakelig, økt eksponering Podatne, zwiększone narażenie Suscetível, exposição aumentada Susceptibil, expunere crescută Чутливий, підвищена експозиція Susceptible, mayor exposición Inayokubali, huhitaji mfiduo zaidi Mottaglig, ökad exponering Duyarlı, artmış maruziyet Чутливий до підвищеної експозиції حساس، مزید نمائش درکار Nhạy cảm, cần tăng phơi nhiễm
|
||||
susceptible, incr. exp. FALSE TRUE FALSE FALSE susceptible, incr. exp. حساس، يحتاج تعرض زائد সংবেদনশীল, অতিরিক্ত এক্সপোজার প্রয়োজন 易感,接触增加 Vnímavý, zvýšená expozice Modtagelig, øget eksponering Gevoelig bij verhoogde blootstelling Altis, lisääntynyt altistuminen Sensible, à forte posologie Empfindlich, erhöhte Belastung Ευαίσθητος, αυξημένη έκθεση संवेदनशील, अधिक संपर्क rentan, perlu paparan tambahan Sensibile, esposizione aumentata 影響を受けやすい、露出が増える 감수성, 노출 증가 필요 Mottakelig, økt eksponering Podatne, zwiększone narażenie Suscetível, exposição aumentada Susceptibil, expunere crescută Чутливий, підвищена експозиція Susceptible, mayor exposición inayokubali, huhitaji mfiduo zaidi Mottaglig, ökad exponering Duyarlı, artmış maruziyet Чутливий до підвищеної експозиції حساس، مزید نمائش درکار nhạy cảm, cần tăng phơi nhiễm
|
||||
Susceptible TRUE FALSE FALSE FALSE Susceptible حساس সংবেদনশীল 易受影响 Vnímavý Modtagelig Gevoelig Altis Sensible Empfindlich Ευαίσθητο संवेदनशील Rentan Sensibile 影響を受けやすい 감수성 있음 Mottakelig Podatny Suscetível Susceptibil Чутливий Susceptible Inayokubali Mottaglig Duyarlı Чутливий حساس Nhạy cảm
|
||||
Incr. exposure TRUE FALSE FALSE FALSE Incr. exposure زيادة التعرض অতিরিক্ত এক্সপোজার 暴露增加 Zvýšená expozice Øget eksponering Verhoogde blootstelling Lisääntynyt altistuminen Forte posologie Erhöhte Belastung Αυξημένη έκθεση अधिक संपर्क Paparan tambahan Esposizione aumentata 曝露量増加 노출 증가 Økt eksponering Większe narażenie Exposição aumentada Expunere crescută Підвищена експозиція Mayor exposición Mfiduo zaidi Ökad exponering Artmış maruziyet Підвищена експозиція زیادہ نمائش Tăng phơi nhiễm
|
||||
Resistant TRUE FALSE FALSE FALSE Resistant مقاوم প্রতিরোধী 耐药性 Rezistentní Resistent Resistent Kestävä Résistant Resistent Ανθεκτικός प्रतिरोधी Tahan Resistente 耐性 내성 Resistent Odporny Resistente Rezistent Стійкий Resistente Sugu Resistent Dayanıklı Стійкий مزاحم Kháng
|
||||
Non-interpretable TRUE FALSE FALSE FALSE Non-interpretable غير قابل للتفسير ব্যাখ্যাতীত 无法解释 Nelze interpretovat Ufortolkelig Niet interpreteerbaar Ei tulkittavissa Non interprétable Nicht interpretierbar Μη ερμηνεύσιμο अव्याख्यायनीय Tidak dapat ditafsirkan Non interpretabile 解釈不可 해석 불가 Utolkelig ikke Niemożliwe do interpretacji Não interpretável Neinterpretabil Непереводимо No interpretable Haieleweki Inte tolkningsbar Yorumlanamaz Непридатний до інтерпретації غیر قابل تشریح Không diễn giải được
|
||||
Intermediate TRUE FALSE FALSE FALSE Intermediate متوسط মধ্যবর্তী 中介 Intermediární Intermediær Intermediair Kohtalaisen herkkä Intermédiaire Intermediär Ενδιάμεσο मध्यम Intermediet Intermedio 中間 중간 Intermediær Średnio wrażliwy Intermediário Intermediar Промежуточный Intermedio Kati Intermediär Orta duyarlı Проміжний درمیانی Trung gian
|
||||
Susceptible, incr. exp. FALSE TRUE FALSE FALSE Susceptible, incr. exp. حساس، يحتاج تعرض زائد সংবেদনশীল, অতিরিক্ত এক্সপোজার প্রয়োজন 敏感,增加暴露 Citlivý, zvýšená expozice Følsom ved øget eksponering Gevoelig bij verhoogde blootstelling Herkkä riittävän suurella annostuksella Sensible à forte posologie Sensibel bei erhöhter Exposition Ευαίσθητο, αυξημένη έκθεση संवेदनशील, अधिक संपर्क Sensitif, paparan ditingkatkan Sensibile, esposizione aumentata 感性、曝露量増加 감수성, 노출 증가 필요 Følsom ved økt eksponering Wrażliwy, zwiększona ekspozycja Suscetível, exposição aumentada Sensibil, expunere crescută Чувствительный при увеличенной экспозиции Sensible, cuando se incrementa la exposición Inayoathirika, mfiduo zaidi Känslig vid ökad exponering Duyarlı, artmış maruziyet Чутливий при підвищеній експозиції حساس، مزید نمائش درکار Nhạy cảm, cần tăng phơi nhiễm
|
||||
susceptible, incr. exp. FALSE TRUE FALSE FALSE susceptible, incr. exp. حساس، يحتاج تعرض زائد সংবেদনশীল, অতিরিক্ত এক্সপোজার প্রয়োজন 敏感,增加暴露 citlivý, zvýšená expozice følsom ved øget eksponering gevoelig bij verhoogde blootstelling herkkä riittävän suurella annostuksella sensible à forte posologie sensibel bei erhöhter Exposition ευαίσθητο, αυξημένη έκθεση संवेदनशील, अधिक संपर्क sensitif, paparan ditingkatkan sensibile, esposizione aumentata 感性、曝露量増加 감수성, 노출 증가 필요 følsom ved økt eksponering wrażliwy, zwiększona ekspozycja suscetível, exposição aumentada sensibil, expunere crescută чувствительный при увеличенной экспозиции sensible, cuando se incrementa la exposición inayoathirika, mfiduo zaidi känslig vid ökad exponering duyarlı, artmış maruziyet чутливий при підвищеній експозиції حساس، مزید نمائش درکار nhạy cảm, cần tăng phơi nhiễm
|
||||
Susceptible TRUE FALSE FALSE FALSE Susceptible حساس সংবেদনশীল 敏感 Citlivý Følsom Gevoelig Herkkä Sensible Sensibel Ευαίσθητο संवेदनशील Sensitif Sensibile 感性 감수성 Følsom Wrażliwy Suscetível Sensibil Чувствительный Sensible Inayoathirika Känslig Duyarlı Чутливий حساس Nhạy cảm
|
||||
Incr. exposure TRUE FALSE FALSE FALSE Incr. exposure زيادة التعرض অতিরিক্ত এক্সপোজার 增加暴露 Zvýšená expozice Øget eksponering Verhoogde blootstelling Riittävän suuri annostus Forte posologie Erhöhte Exposition Αυξημένη έκθεση अधिक संपर्क Paparan ditingkatkan Esposizione aumentata 曝露量増加 노출 증가 Økt eksponering Zwiększona ekspozycja Exposição aumentada Expunere crescută Увеличенная экспозиция Mayor exposición Mfiduo zaidi Ökad exponering Artmış maruziyet Підвищена експозиція زیادہ نمائش Tăng phơi nhiễm
|
||||
Resistant TRUE FALSE FALSE FALSE Resistant مقاوم প্রতিরোধী 耐药 Rezistentní Resistent Resistent Resistentti Résistant Resistent Ανθεκτικό प्रतिरोधी Resisten Resistente 耐性 내성 Resistent Oporny Resistente Rezistent Резистентный Resistente Sugu Resistent Dirençli Резистентний مزاحم Kháng
|
||||
Non-interpretable TRUE FALSE FALSE FALSE Non-interpretable غير قابل للتفسير ব্যাখ্যাতীত 无法判读 Nelze interpretovat Ufortolkelig Niet interpreteerbaar Ei tulkittavissa Non interprétable Nicht interpretierbar Μη ερμηνεύσιμο अव्याख्यायनीय Tidak dapat ditafsirkan Non interpretabile 解釈不可 해석 불가 Ikke tolkbar Niemożliwe do interpretacji Não interpretável Neinterpretabil Не интерпретируемый No interpretable Haieleweki Ej tolkningsbar Yorumlanamaz Непридатний до інтерпретації غیر قابل تشریح Không diễn giải được
|
||||
Susceptible dose-dependent TRUE FALSE FALSE FALSE Susceptible dose-dependent حساس حسب الجرعة ডোজ-নির্ভর সংবেদনশীল 剂量依赖性敏感 Citlivý v závislosti na dávce Følsom, dosisafhængig Gevoelig, dosisafhankelijk Herkkä, annoksesta riippuva Sensible dose-dépendant Sensibel, dosisabhängig Ευαίσθητο εξαρτώμενο από τη δόση खुराक-निर्भर संवेदनशील Sensitif tergantung dosis Sensibile dose-dipendente 用量依存的感性 용량 의존적 감수성 Følsom, doseavhengig Wrażliwy zależnie od dawki Suscetível dose-dependente Sensibil dependent de doză Дозозависимо чувствительный Sensible dependiente de la dosis Inayoathirika kulingana na dozi Känslig, dosberoende Doza bağlı duyarlı Дозозалежно чутливий خوراک پر منحصر حساس Nhạy cảm phụ thuộc liều
|
||||
Non-susceptible TRUE FALSE FALSE FALSE Non-susceptible غير حساس অসংবেদনশীল 不敏感 Necitlivý Ikke-følsom Niet-gevoelig Ei herkkä Non sensible Nicht sensibel Μη ευαίσθητο असंवेदनशील Tidak sensitif Non sensibile 非感性 비감수성 Ikke-følsom Niewrażliwy Não suscetível Nesensibil Нечувствительный No sensible Isiyoathirika Ej känslig Duyarlı değil Нечутливий غیر حساس Không nhạy cảm
|
||||
Non-wildtype TRUE FALSE FALSE FALSE Non-wildtype غير النمط البري অ-বন্য প্রকার 非野生型 Jiný než divoký typ Ikke-vildtype Niet-wildtype Ei-villityyppi Type non sauvage Nicht-Wildtyp Μη άγριος τύπος गैर-वन्य प्रकार Bukan tipe liar Tipo non selvatico 非野生型 비야생형 Ikke-villtype Typ inny niż dziki Tipo não selvagem Tip non-sălbatic Не дикий тип Tipo no salvaje Si aina ya asili Icke-vildtyp Yabanıl tip dışı Не дикий тип غیر جنگلی قسم Không phải kiểu hoang dã
|
||||
Wildtype TRUE FALSE FALSE FALSE Wildtype النمط البري বন্য প্রকার 野生型 Divoký typ Vildtype Wildtype Villityyppi Type sauvage Wildtyp Άγριος τύπος वन्य प्रकार Tipe liar Tipo selvatico 野生型 야생형 Villtype Typ dziki Tipo selvagem Tip sălbatic Дикий тип Tipo salvaje Aina ya asili Vildtyp Yabanıl tip Дикий тип جنگلی قسم Kiểu hoang dã
|
||||
antibiotic TRUE TRUE FALSE FALSE antibiotic مضاد حيوي অ্যান্টিবায়োটিক 抗生素 antibiotikum antibiotikum antibioticum antibiootti antibiotique Antibiotikum αντιβιοτικό प्रतिजैविक Antibiotik antibiotico 抗生物質 항생제 Antibiotikum antybiotyk antibiótico antibiotic антибиотик antibiótico antibayotiki antibiotika Antibiyotik антибіотик اینٹی بایوٹک Kháng sinh
|
||||
Antibiotic TRUE TRUE FALSE FALSE Antibiotic مضاد حيوي অ্যান্টিবায়োটিক 抗生素 Antibiotikum Antibiotikum Antibioticum Antibiootti Antibiotique Antibiotikum Αντιβιοτικό प्रतिजैविक Antibiotik Antibiotico 抗生物質 항생제 Antibiotikum Antybiotyk Antibiótico Antibiotic Антибиотик Antibiótico Antibayotiki Antibiotika Antibiyotik Антибіотик اینٹی بایوٹک Kháng sinh
|
||||
Drug TRUE TRUE FALSE FALSE Drug دواء ড্রাগ 药物 Lék Lægemiddel Middel Lääke Médicament Medikament Φάρμακο दवा Obat Droga 薬剤 약물 Legemiddel Lek Droga Medicament Лекарство Fármaco Dawa Läkemedel İlaç Лікарський засіб Dوا Nhóm thuốc
|
||||
|
||||
|
+14
-14
@@ -35,21 +35,21 @@ scale_fill_mic(keep_operators = "edges", mic_range = NULL, ...)
|
||||
scale_x_sir(
|
||||
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
|
||||
language = get_AMR_locale(),
|
||||
eucast_I = getOption("AMR_guideline", "EUCAST") \%like\% "EUCAST",
|
||||
eucast_I = plot_name_of_I(getOption("AMR_guideline", "EUCAST")) != "Intermediate",
|
||||
...
|
||||
)
|
||||
|
||||
scale_colour_sir(
|
||||
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
|
||||
language = get_AMR_locale(),
|
||||
eucast_I = getOption("AMR_guideline", "EUCAST") \%like\% "EUCAST",
|
||||
eucast_I = plot_name_of_I(getOption("AMR_guideline", "EUCAST")) != "Intermediate",
|
||||
...
|
||||
)
|
||||
|
||||
scale_fill_sir(
|
||||
colours_SIR = c(S = "#3CAEA3", SDD = "#8FD6C4", I = "#F6D55C", R = "#ED553B"),
|
||||
language = get_AMR_locale(),
|
||||
eucast_I = getOption("AMR_guideline", "EUCAST") \%like\% "EUCAST",
|
||||
eucast_I = plot_name_of_I(getOption("AMR_guideline", "EUCAST")) != "Intermediate",
|
||||
...
|
||||
)
|
||||
|
||||
@@ -158,11 +158,11 @@ theme_sir()
|
||||
|
||||
\item{...}{Arguments passed on to methods.}
|
||||
|
||||
\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{colours_SIR}{Colours to use for filling in the bars, must be a vector of one, three or four values (in the order S, SDD, I and R), or a named vector with at least the names S, I and R. With three values or without a name SDD, SDD gets the colour of S. 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} to prevent translation.}
|
||||
|
||||
\item{eucast_I}{A \link{logical} to indicate whether the 'I' must be interpreted as "Susceptible, under increased exposure". Will be \code{TRUE} if the default \link[=as.sir]{AMR interpretation guideline} is set to EUCAST (which is the default). With \code{FALSE}, it will be interpreted as "Intermediate".}
|
||||
\item{eucast_I}{A \link{logical} to indicate whether the 'I' must be interpreted as "Susceptible, under increased exposure". Will be \code{TRUE} if the default \link[=as.sir]{AMR interpretation guideline} is set to EUCAST 2019 or later (which is the default). With \code{FALSE}, it will be interpreted as "Intermediate".}
|
||||
|
||||
\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()}}).}
|
||||
|
||||
@@ -198,12 +198,12 @@ The \code{autoplot()} functions return a \code{\link[ggplot2:ggplot]{ggplot}} mo
|
||||
\description{
|
||||
Functions to plot classes \code{sir}, \code{mic} and \code{disk}, with support for base \R and \code{ggplot2}.
|
||||
|
||||
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.
|
||||
Especially the \verb{scale_*_mic()} functions are relevant wrappers to plot MIC values for \code{ggplot2}. They allow custom MIC ranges and to plot intermediate log2 levels for missing MIC values.
|
||||
}
|
||||
\details{
|
||||
\subsection{The \verb{scale_*_mic()} Functions}{
|
||||
|
||||
The functions \code{\link[=scale_x_mic]{scale_x_mic()}}, \code{\link[=scale_y_mic]{scale_y_mic()}}, \code{\link[=scale_colour_mic]{scale_colour_mic()}}, and \code{\link[=scale_fill_mic]{scale_fill_mic()}} functions allow to plot the \link[=as.mic]{mic} class (MIC values) on a continuous, logarithmic scale.
|
||||
The functions \code{\link[=scale_x_mic]{scale_x_mic()}}, \code{\link[=scale_y_mic]{scale_y_mic()}}, \code{\link[=scale_colour_mic]{scale_colour_mic()}}, and \code{\link[=scale_fill_mic]{scale_fill_mic()}} allow to plot the \link[=as.mic]{mic} class (MIC values) on a continuous, logarithmic scale.
|
||||
|
||||
There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class \link[=as.mic]{mic}.
|
||||
|
||||
@@ -212,7 +212,7 @@ When manually added though, they allow to rescale the MIC range with an 'inside'
|
||||
|
||||
\subsection{The \verb{scale_*_sir()} Functions}{
|
||||
|
||||
The functions \code{\link[=scale_x_sir]{scale_x_sir()}}, \code{\link[=scale_colour_sir]{scale_colour_sir()}}, and \code{\link[=scale_fill_sir]{scale_fill_sir()}} functions allow to plot the \link[=as.sir]{sir} class in the right order (S < SDD < I < R < NI < WT < NWT < NS).
|
||||
The functions \code{\link[=scale_x_sir]{scale_x_sir()}}, \code{\link[=scale_colour_sir]{scale_colour_sir()}}, and \code{\link[=scale_fill_sir]{scale_fill_sir()}} allow to plot the \link[=as.sir]{sir} class in the right order (S < SDD < I < R < NI < WT < NWT < NS).
|
||||
|
||||
There is normally no need to add these scale functions to your plot, as they are applied automatically when plotting values of class \link[=as.sir]{sir}.
|
||||
|
||||
@@ -227,10 +227,10 @@ This package contains more functions that extend the \code{ggplot2} package, to
|
||||
\item \code{\link[=scale_y_percent]{scale_y_percent()}} transforms the y axis to a 0 to 100\% range using \code{\link[ggplot2:scale_y_continuous]{ggplot2::scale_y_continuous()}}.
|
||||
\item \code{\link[=scale_sir_colours]{scale_sir_colours()}} allows to set colours to any aesthetic, even for \code{shape} or \code{linetype}.
|
||||
\item \code{\link[=theme_sir]{theme_sir()}} is a \link[ggplot2:theme]{ggplot2 theme} with minimal distraction.
|
||||
\item \code{\link[=labels_sir_count]{labels_sir_count()}} print datalabels on the bars with percentage and number of isolates, using \code{\link[ggplot2:geom_text]{ggplot2::geom_text()}}.
|
||||
\item \code{\link[=labels_sir_count]{labels_sir_count()}} prints data labels on the bars with percentage and number of isolates, using \code{\link[ggplot2:geom_text]{ggplot2::geom_text()}}.
|
||||
}
|
||||
|
||||
The interpretation of "I" will be named "Increased exposure" for all EUCAST guidelines since 2019, and will be named "Intermediate" in all other cases.
|
||||
The interpretation of "I" will be named "Susceptible, incr. exp." (susceptible, 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, the default guideline is EUCAST 2026, unless the package option \code{\link[=AMR-options]{AMR_guideline}} is set. See \code{\link[=as.sir]{as.sir()}} for more information.
|
||||
}
|
||||
@@ -254,7 +254,7 @@ if (require("ggplot2")) {
|
||||
}
|
||||
|
||||
if (require("ggplot2")) {
|
||||
# support for 27 languages, various guidelines, and many options
|
||||
# support for all languages in ?translate, various guidelines, and many options
|
||||
autoplot(some_disk_values,
|
||||
mo = "Escherichia coli", ab = "cipro",
|
||||
guideline = "CLSI", language = "no",
|
||||
@@ -351,8 +351,8 @@ if (require("ggplot2")) {
|
||||
) +
|
||||
theme_minimal() +
|
||||
geom_boxplot(fill = NA, colour = "grey30") +
|
||||
geom_jitter(width = 0.25)
|
||||
labs(title = "scale_y_mic()/scale_colour_sir() automatically applied")
|
||||
geom_jitter(width = 0.25) +
|
||||
labs(title = "scale_y_mic()/scale_colour_sir() automatically applied")
|
||||
|
||||
mic_sir_plot
|
||||
}
|
||||
@@ -361,7 +361,7 @@ if (require("ggplot2")) {
|
||||
scale_y_mic(mic_range = c(0.005, 32), name = "Our MICs!") +
|
||||
scale_colour_sir(
|
||||
language = "pt", # Portuguese
|
||||
name = "Support in 28 languages"
|
||||
name = "Support in many languages"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,10 @@ test_that("test-antibiogram.R", {
|
||||
expect_false(identical(as.data.frame(wisca_all), as.data.frame(wisca_known)))
|
||||
if (AMR:::pkg_is_available("dplyr", min_version = "1.0.0", also_load = TRUE)) {
|
||||
ab_grouped <- tryCatch(
|
||||
example_isolates %>% group_by(ward) %>% antibiogram(antimicrobials = "GEN", minimum = 0, formatting_type = 1, guideline = "EUCAST"),
|
||||
# pathogen names are translated, so test in English, which must also hold on systems in another language
|
||||
example_isolates %>%
|
||||
group_by(ward) %>%
|
||||
antibiogram(antimicrobials = "GEN", minimum = 0, formatting_type = 1, guideline = "EUCAST", language = "en"),
|
||||
warning = function(w) conditionMessage(w)
|
||||
)
|
||||
expect_inherits(ab_grouped, "antibiogram")
|
||||
|
||||
@@ -114,5 +114,90 @@ test_that("test-plotting.R", {
|
||||
scale_x_sir(),
|
||||
"gg"
|
||||
)
|
||||
|
||||
# named colours are matched by name, and SDD, S/I and I/R follow S and R
|
||||
expect_identical(AMR:::expand_SIR_colours(c(R = "r", I = "i", SDD = "d", S = "s")), c("s", "d", "i", "r", "s", "r"))
|
||||
expect_identical(AMR:::expand_SIR_colours(c(S = "s", I = "i", R = "r")), c("s", "s", "i", "r", "s", "r"))
|
||||
expect_identical(AMR:::expand_SIR_colours(c("s", "i", "r")), c("s", "s", "i", "r", "s", "r"))
|
||||
expect_error(AMR:::expand_SIR_colours(c(S = "s", I = "i", X = "r")))
|
||||
|
||||
# colours of SIR bar plots follow the SIR values
|
||||
sir_values <- as.sir(c("S", "S", "R", "NI", "NS"))
|
||||
keep <- AMR:::plot_sir_levels_to_keep(sir_values, table(sir_values))
|
||||
expect_identical(names(table(sir_values))[keep], c("S", "R", "NI", "NS"))
|
||||
p <- autoplot(sir_values)
|
||||
expect_identical(as.character(p$data$x), c("S", "R", "NI", "NS"))
|
||||
expect_identical(unique(ggplot_build(p)$data[[1]]$fill), c("#3CAEA3", "#ED553B", "grey30"))
|
||||
|
||||
# SDD in disk diffusion plots
|
||||
p <- autoplot(as.disk(15:30), mo = "Escherichia coli", ab = "cefepime", guideline = "CLSI 2025", language = "en")
|
||||
expect_true("(SDD) Susceptible dose-dependent" %in% as.character(p$data$cols))
|
||||
expect_false(anyNA(p$data$cols))
|
||||
|
||||
# colours and labels are named by, and cover, all SIR levels
|
||||
expect_identical(names(AMR:::plot_sir_colour_values(AMR:::expand_SIR_colours("red"))), AMR:::VALID_SIR_LEVELS)
|
||||
expect_identical(names(AMR:::plot_sir_label_values("EUCAST")), AMR:::VALID_SIR_LEVELS)
|
||||
|
||||
# arguments are passed on
|
||||
expect_identical(scale_x_sir(name = "Interpretation")$name, "Interpretation")
|
||||
expect_identical(scale_fill_sir(values = c(S = "black"))$palette(1)[["S"]], "black")
|
||||
expect_identical(scale_fill_sir(values = c(S = "black"))$palette(1)[["R"]], "#ED553B")
|
||||
expect_error(scale_fill_sir(values = c("black", "white", "grey")))
|
||||
expect_warning(scale_x_sir(values = c(S = "black")))
|
||||
expect_identical(AMR:::plot_count_ticks(3), c(0, 1, 2, 3))
|
||||
expect_identical(AMR:::plot_name_of_I("EUCAST"), "Susceptible, incr. exp.")
|
||||
expect_identical(AMR:::plot_name_of_I("EUCAST 2018"), "Intermediate")
|
||||
|
||||
# unquoted column names in facet_sir() are not evaluated, also not if an object with that name exists
|
||||
antibiotic <- "some other column"
|
||||
expect_identical(facet_sir(antibiotic)$params$facets, facet_sir("antibiotic")$params$facets)
|
||||
|
||||
# the default of eucast_I follows the guideline option
|
||||
expect_identical(scale_fill_sir(language = "en")$labels("I"), "(I) Susceptible, incr. exp.")
|
||||
old_option <- options(AMR_guideline = "EUCAST 2018")
|
||||
expect_identical(scale_fill_sir(language = "en")$labels("I"), "(I) Intermediate")
|
||||
options(old_option)
|
||||
|
||||
# keep_operators = TRUE/FALSE equals "all"/"none"
|
||||
mic_labels <- function(keep_operators) {
|
||||
p <- ggplot(data.frame(m = as.mic(c(">=8", "2", "<=0.5"))), aes(m, 1)) +
|
||||
geom_point() +
|
||||
scale_x_mic(keep_operators = keep_operators)
|
||||
ggplot_build(p)$layout$panel_params[[1]]$x$get_labels()
|
||||
}
|
||||
expect_identical(mic_labels(TRUE), mic_labels("all"))
|
||||
expect_identical(mic_labels(FALSE), mic_labels("none"))
|
||||
expect_false(identical(mic_labels(TRUE), mic_labels(FALSE)))
|
||||
}
|
||||
|
||||
# base R plots: texts in the legend (drawn with text()) and bar names (drawn with axis())
|
||||
recorded_strings <- function(expr, fn) {
|
||||
pdf(NULL)
|
||||
dev.control("enable")
|
||||
on.exit(dev.off())
|
||||
force(expr)
|
||||
unlist(lapply(recordPlot()[[1]], function(call) {
|
||||
if (identical(call[[2]][[1]]$name, fn)) {
|
||||
as.character(call[[2]][[if (fn == "C_text") 3 else 4]])
|
||||
}
|
||||
}))
|
||||
}
|
||||
mic_values <- as.mic(c(0.25, 0.25, 4, 32))
|
||||
|
||||
# the legend is based on the interpretation, so SDD is not shown when it has the colour of S
|
||||
expect_identical(
|
||||
recorded_strings(plot(mic_values, mo = "Escherichia coli", ab = "AMC", language = "en", colours_SIR = c("green", "yellow", "red")), "C_text"),
|
||||
c("(S) Susceptible", "(R) Resistant")
|
||||
)
|
||||
# zone diameters run from resistant to susceptible, and so does the legend
|
||||
expect_identical(
|
||||
recorded_strings(plot(as.disk(15:30), mo = "Escherichia coli", ab = "cefepime", guideline = "CLSI 2025", language = "en"), "C_text"),
|
||||
c("(R) Resistant", "(SDD) Susceptible dose-dependent", "(S) Susceptible")
|
||||
)
|
||||
# barplot() for MIC values passes on language and expand
|
||||
expect_identical(
|
||||
recorded_strings(barplot(mic_values, mo = "Escherichia coli", ab = "AMC", language = "nl"), "C_text"),
|
||||
c("(S) Gevoelig", "(R) Resistent")
|
||||
)
|
||||
expect_true(length(recorded_strings(barplot(mic_values, expand = TRUE), "C_axis")) > length(recorded_strings(barplot(mic_values, expand = FALSE), "C_axis")))
|
||||
})
|
||||
Reference in new issue
Block a user