From ba4dc20cf382fe1a064577d0a48bd95da8c05baa Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Thu, 30 May 2024 16:39:59 +0200 Subject: [PATCH] autoplot fix --- DESCRIPTION | 2 +- NEWS.md | 2 +- R/plot.R | 5 +++-- R/sir.R | 12 ++++++------ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0f0ff48a..95ce8820 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: AMR -Version: 2.1.1.9034 +Version: 2.1.1.9035 Date: 2024-05-30 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) diff --git a/NEWS.md b/NEWS.md index 363258d5..9ff6cb13 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 2.1.1.9034 +# AMR 2.1.1.9035 *(this beta version will eventually become v3.0. We're happy to reach a new major milestone soon, which will be all about the new One Health support!)* diff --git a/R/plot.R b/R/plot.R index 92da3a38..8cf4ab65 100755 --- a/R/plot.R +++ b/R/plot.R @@ -760,9 +760,10 @@ autoplot.sir <- function(object, } df <- as.data.frame(table(object), stringsAsFactors = TRUE) - colnames(df) <- c("sir", "count") + colnames(df) <- c("x", "n") + df <- df[!(df$n == 0 & df$x %in% c("SDD", "I", "N")), , drop = FALSE] ggplot2::ggplot(df) + - ggplot2::geom_col(ggplot2::aes(x = sir, y = count, fill = sir)) + + 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( diff --git a/R/sir.R b/R/sir.R index d264514f..78688c1f 100755 --- a/R/sir.R +++ b/R/sir.R @@ -907,15 +907,15 @@ as_sir_method <- function(method_short, same_ab <- generalise_antibiotic_name(ab) == generalise_antibiotic_name(agent_name) same_ab.bak <- generalise_antibiotic_name(ab.bak) == generalise_antibiotic_name(agent_name) agent_formatted[same_ab.bak] <- paste0(agent_formatted[same_ab.bak], " (", ab, ")") - agent_formatted[same_ab.bak & !same_ab] <- paste0(agent_formatted[same_ab.bak & !same_ab], - " (", ifelse(ab.bak[same_ab.bak & !same_ab] == ab[same_ab.bak & !same_ab], + agent_formatted[!same_ab.bak & !same_ab] <- paste0(agent_formatted[!same_ab.bak & !same_ab], + " (", ifelse(ab.bak[!same_ab.bak & !same_ab] == ab[!same_ab.bak & !same_ab], "", - paste0(ab[same_ab.bak & !same_ab], ", ")), - agent_name[same_ab.bak & !same_ab], + paste0(ab[!same_ab.bak & !same_ab], ", ")), + agent_name[!same_ab.bak & !same_ab], ")") - # this intro text will also be printed in the progress bar in the `progress` package is installed + # this intro text will also be printed in the progress bar if the `progress` package is installed intro_txt <- paste0("Interpreting ", method_long, ": ", ifelse(isTRUE(list(...)$is_data.frame), "column ", ""), - ifelse(length(agent_formatted) == 1, agent_formatted, ""), + ifelse(length(unique(agent_formatted)) == 1, unique(agent_formatted), vector_and(ab, quotes = FALSE)), mo_var_found, ifelse(identical(reference_data, AMR::clinical_breakpoints), paste0(", ", font_bold(guideline_coerced)),