mirror of https://github.com/msberends/AMR.git
(v2.1.1.9080) fix `rescale_mic()` for an outside MIC range
This commit is contained in:
parent
1ca40e8d67
commit
a558f4c121
|
@ -1,5 +1,5 @@
|
|||
Package: AMR
|
||||
Version: 2.1.1.9079
|
||||
Version: 2.1.1.9080
|
||||
Date: 2024-09-24
|
||||
Title: Antimicrobial Resistance Data Analysis
|
||||
Description: Functions to simplify and standardise antimicrobial resistance (AMR)
|
||||
|
|
2
NEWS.md
2
NEWS.md
|
@ -1,4 +1,4 @@
|
|||
# AMR 2.1.1.9079
|
||||
# AMR 2.1.1.9080
|
||||
|
||||
*(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! Install this beta using [the instructions here](https://msberends.github.io/AMR/#latest-development-version).)*
|
||||
|
||||
|
|
6
R/mic.R
6
R/mic.R
|
@ -304,9 +304,9 @@ rescale_mic <- function(x, mic_range, keep_operators = "edges", as.mic = TRUE) {
|
|||
|
||||
# create a manual factor with levels only within desired range
|
||||
expanded <- plotrange_as_table(x,
|
||||
expand = TRUE,
|
||||
keep_operators = ifelse(keep_operators == "edges", "none", keep_operators),
|
||||
mic_range = mic_range)
|
||||
expand = TRUE,
|
||||
keep_operators = ifelse(keep_operators == "edges", "none", keep_operators),
|
||||
mic_range = mic_range)
|
||||
if (keep_operators == "edges") {
|
||||
names(expanded)[1] <- paste0("<=", names(expanded)[1])
|
||||
names(expanded)[length(expanded)] <- paste0(">=", names(expanded)[length(expanded)])
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
#' # Plotting using scale_x_mic()
|
||||
#' \donttest{
|
||||
#' if (require("ggplot2")) {
|
||||
#' mic_plot <- ggplot(data.frame(mics = as.mic(c(0.125, "<=4", 4, 8, 32, ">=32")),
|
||||
#' mic_plot <- ggplot(data.frame(mics = as.mic(c(0.25, "<=4", 4, 8, 32, ">=32")),
|
||||
#' counts = c(1, 1, 2, 2, 3, 3)),
|
||||
#' aes(mics, counts)) +
|
||||
#' geom_col()
|
||||
|
@ -92,8 +92,13 @@
|
|||
#' }
|
||||
#' if (require("ggplot2")) {
|
||||
#' mic_plot +
|
||||
#' scale_x_mic(mic_range = c(1, 128)) +
|
||||
#' labs(title = "with scale_x_mic() using a manual range")
|
||||
#' 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")
|
||||
#' }
|
||||
#'
|
||||
#' if (require("ggplot2")) {
|
||||
|
@ -795,7 +800,14 @@ plotrange_as_table <- function(x, expand, keep_operators = "all", mic_range = NU
|
|||
x <- as.mic(x, keep_operators = keep_operators)
|
||||
if (expand == TRUE) {
|
||||
# expand range for MIC by adding common intermediate factors levels
|
||||
extra_range <- COMMON_MIC_VALUES[COMMON_MIC_VALUES > min(x, na.rm = TRUE) & COMMON_MIC_VALUES < max(x, na.rm = TRUE)]
|
||||
if (!is.null(mic_range) && !all(is.na(mic_range))) {
|
||||
# base on mic_range
|
||||
`%na_or%` <- function(x, y) if (is.na(x)) y else x
|
||||
extra_range <- COMMON_MIC_VALUES[COMMON_MIC_VALUES >= (mic_range[1] %na_or% min(x, na.rm = TRUE)) & COMMON_MIC_VALUES <= (mic_range[2] %na_or% max(x, na.rm = TRUE))]
|
||||
} else {
|
||||
# base on x
|
||||
extra_range <- COMMON_MIC_VALUES[COMMON_MIC_VALUES > min(x, na.rm = TRUE) & COMMON_MIC_VALUES < max(x, na.rm = TRUE)]
|
||||
}
|
||||
# remove the ones that are in 25% range of user values
|
||||
extra_range <- extra_range[!vapply(FUN.VALUE = logical(1), extra_range, function(r) any(abs(r - x) / x < 0.25, na.rm = TRUE))]
|
||||
nms <- extra_range
|
2
R/sir.R
2
R/sir.R
|
@ -1376,7 +1376,7 @@ as_sir_method <- function(method_short,
|
|||
} else {
|
||||
site <- paste0("body site '", site, "'")
|
||||
}
|
||||
if (nrow(breakpoints_current) == 1 && all(breakpoints_current$uti == TRUE) && any(uti_current %in% c(FALSE, NA)) && message_not_thrown_before("as.sir", "uti", ab_current)) {
|
||||
if (nrow(breakpoints_current) == 1 && all(breakpoints_current$uti == TRUE) && is.na(uti_current) && message_not_thrown_before("as.sir", "uti", ab_current)) {
|
||||
# only UTI breakpoints available
|
||||
notes_current <- c(notes_current, paste0("Breakpoints for ", font_bold(ab_formatted), " in ", mo_formatted, " are only available for (uncomplicated) urinary tract infections (UTI); assuming `uti = TRUE`."))
|
||||
} else if (nrow(breakpoints_current) > 1 && length(unique(breakpoints_current$site)) > 1 && any(is.na(uti_current)) && all(c(TRUE, FALSE) %in% breakpoints_current$uti, na.rm = TRUE) && message_not_thrown_before("as.sir", "siteUTI", mo_current, ab_current)) {
|
||||
|
|
13
man/plot.Rd
13
man/plot.Rd
|
@ -1,5 +1,5 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/plot.R
|
||||
% Please edit documentation in R/plotting.R
|
||||
\name{plot}
|
||||
\alias{plot}
|
||||
\alias{scale_x_mic}
|
||||
|
@ -180,7 +180,7 @@ plot(some_disk_values, mo = "Escherichia coli", ab = "cipro", language = "nl")
|
|||
# Plotting using scale_x_mic()
|
||||
\donttest{
|
||||
if (require("ggplot2")) {
|
||||
mic_plot <- ggplot(data.frame(mics = as.mic(c(0.125, "<=4", 4, 8, 32, ">=32")),
|
||||
mic_plot <- ggplot(data.frame(mics = as.mic(c(0.25, "<=4", 4, 8, 32, ">=32")),
|
||||
counts = c(1, 1, 2, 2, 3, 3)),
|
||||
aes(mics, counts)) +
|
||||
geom_col()
|
||||
|
@ -199,8 +199,13 @@ if (require("ggplot2")) {
|
|||
}
|
||||
if (require("ggplot2")) {
|
||||
mic_plot +
|
||||
scale_x_mic(mic_range = c(1, 128)) +
|
||||
labs(title = "with scale_x_mic() using a manual range")
|
||||
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")
|
||||
}
|
||||
|
||||
if (require("ggplot2")) {
|
||||
|
|
Loading…
Reference in New Issue