mirror of
https://github.com/msberends/AMR.git
synced 2026-11-15 22:50:50 +01:00
(v3.0.1.9152) Let a named colours_SIR without S, I or R use the default colours for these, which fixes the example of ggplot_sir() with colours = c(SI = "yellow"), let ggplot_sir() pass the facet as a value to facet_sir(), and make the test of the eucast_I default independent of the AMR_guideline option
This commit is contained in:
1 parent
43accd35d1
commit
08aa47842e
7 files changed
+23
-11
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
Package: AMR
|
||||
Version: 3.0.1.9151
|
||||
Version: 3.0.1.9152
|
||||
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.9151
|
||||
# AMR 3.0.1.9152
|
||||
|
||||
Planned as v3.1.0, mid October 2026.
|
||||
|
||||
@@ -136,7 +136,7 @@ Planned as v3.1.0, mid October 2026.
|
||||
* 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.
|
||||
* A named `colours_SIR` is now matched by name in all plotting functions, and S, I and R get their default colour if not set. 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`
|
||||
|
||||
+2
-1
@@ -271,7 +271,8 @@ ggplot_sir <- function(data,
|
||||
}
|
||||
|
||||
if (!is.null(facet)) {
|
||||
p <- p + facet_sir(facet = facet, nrow = nrow)
|
||||
# pass the value, as facet_sir() takes an unquoted name as column name
|
||||
p <- p + do.call(facet_sir, list(facet = facet, nrow = nrow))
|
||||
}
|
||||
|
||||
p <- p + ggplot2::labs(
|
||||
|
||||
+4
-5
@@ -39,7 +39,7 @@
|
||||
#' @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 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 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 any of the names S, SDD, I, R, SI and IR. Missing names S, I and R get the default colour, and 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".
|
||||
@@ -1484,10 +1484,9 @@ expand_SIR_colours <- function(colours_SIR, unname = TRUE) {
|
||||
all(names(colours_SIR) %in% sir_order),
|
||||
"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."
|
||||
)
|
||||
# S, I and R get the default colours, unless set, e.g. for ggplot_sir(colours = c(SI = "yellow"))
|
||||
default_colours <- c(S = "#3CAEA3", I = "#F6D55C", R = "#ED553B")
|
||||
colours_SIR[setdiff(names(default_colours), names(colours_SIR))] <- default_colours[setdiff(names(default_colours), names(colours_SIR))]
|
||||
}
|
||||
# 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"]]
|
||||
|
||||
+1
-1
@@ -158,7 +158,7 @@ theme_sir()
|
||||
|
||||
\item{...}{Arguments passed on to methods.}
|
||||
|
||||
\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{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 any of the names S, SDD, I, R, SI and IR. Missing names S, I and R get the default colour, and 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.}
|
||||
|
||||
|
||||
@@ -59,6 +59,13 @@ test_that("test-ggplot_sir.R", {
|
||||
ggplot_sir(x = "antibiotic", facet = "interpretation"),
|
||||
"gg"
|
||||
)
|
||||
# the facet is passed on as value, so the plot can be built
|
||||
expect_inherits(
|
||||
ggplot_build(example_isolates %>%
|
||||
select(AMC, CIP) %>%
|
||||
ggplot_sir(x = "interpretation", facet = "antibiotic")),
|
||||
"ggplot_built"
|
||||
)
|
||||
|
||||
expect_equal(
|
||||
(example_isolates %>%
|
||||
|
||||
@@ -120,6 +120,8 @@ test_that("test-plotting.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")))
|
||||
# missing names S, I and R get the default colours, as in the example of ggplot_sir()
|
||||
expect_identical(AMR:::expand_SIR_colours(c(SI = "y")), c("#3CAEA3", "#3CAEA3", "#F6D55C", "#ED553B", "y", "#ED553B"))
|
||||
|
||||
# colours of SIR bar plots follow the SIR values
|
||||
sir_values <- as.sir(c("S", "S", "R", "NI", "NS"))
|
||||
@@ -153,8 +155,11 @@ test_that("test-plotting.R", {
|
||||
expect_identical(facet_sir(antibiotic)$params$facets, facet_sir("antibiotic")$params$facets)
|
||||
|
||||
# the default of eucast_I follows the guideline option
|
||||
old_option <- options(AMR_guideline = "EUCAST")
|
||||
expect_identical(scale_fill_sir(language = "en")$labels("I"), "(I) Susceptible, incr. exp.")
|
||||
old_option <- options(AMR_guideline = "EUCAST 2018")
|
||||
options(AMR_guideline = "EUCAST 2018")
|
||||
expect_identical(scale_fill_sir(language = "en")$labels("I"), "(I) Intermediate")
|
||||
options(AMR_guideline = "CLSI")
|
||||
expect_identical(scale_fill_sir(language = "en")$labels("I"), "(I) Intermediate")
|
||||
options(old_option)
|
||||
|
||||
|
||||
Reference in new issue
Block a user