1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 14:01:55 +02:00

(v1.1.0.9021) 1st isolates update

This commit is contained in:
2020-05-28 10:51:56 +02:00
parent 86d44054f0
commit d9a4b0bcaf
51 changed files with 483 additions and 1106 deletions

View File

@ -304,7 +304,7 @@ rsi_predict <- resistance_predict
#' @exportMethod plot.mic
#' @export
#' @importFrom graphics plot axis arrows points
#' @importFrom graphics axis arrows points
#' @rdname resistance_predict
plot.resistance_predict <- function(x, main = paste("Resistance Prediction of", x_name), ...) {
x_name <- paste0(ab_name(attributes(x)$ab), " (", attributes(x)$ab, ")")
@ -314,6 +314,12 @@ plot.resistance_predict <- function(x, main = paste("Resistance Prediction of",
} else {
ylab <- "%IR"
}
# get plot() generic; this was moved from the 'graphics' pkg to the 'base' pkg in R 4.0.0
if (as.integer(R.Version()$major) >= 4) {
plot <- get("plot", envir = asNamespace("base"))
} else {
plot <- get("plot", envir = asNamespace("graphics"))
}
plot(x = x$year,
y = x$value,
ylim = c(0, 1),

26
R/rsi.R
View File

@ -563,25 +563,20 @@ summary.rsi <- function(object, ...) {
#' @exportMethod plot.rsi
#' @export
#' @importFrom graphics plot text
#' @importFrom graphics text axis
#' @noRd
plot.rsi <- function(x,
lwd = 2,
ylim = NULL,
ylab = "Percentage",
xlab = "Antimicrobial Interpretation",
main = paste("Susceptibility Analysis of", deparse(substitute(x))),
main = paste("Resistance Overview of", deparse(substitute(x))),
axes = FALSE,
...) {
suppressWarnings(
data <- data.frame(x = x,
y = 1,
stringsAsFactors = TRUE) %>%
group_by(x) %>%
summarise(n = sum(y)) %>%
filter(!is.na(x)) %>%
mutate(s = round((n / sum(n)) * 100, 1))
)
data <- as.data.frame(table(x), stringsAsFactors = FALSE)
colnames(data) <- c("x", "n")
data$s <- round((data$n / sum(data$n)) * 100, 1)
if (!"S" %in% data$x) {
data <- rbind(data, data.frame(x = "S", n = 0, s = 0))
}
@ -592,10 +587,17 @@ plot.rsi <- function(x,
data <- rbind(data, data.frame(x = "R", n = 0, s = 0))
}
# don't use as.rsi() here, it will confuse plot()
data$x <- factor(data$x, levels = c("S", "I", "R"), ordered = TRUE)
ymax <- if_else(max(data$s) > 95, 105, 100)
# get plot() generic; this was moved from the 'graphics' pkg to the 'base' pkg in R 4.0.0
if (as.integer(R.Version()$major) >= 4) {
plot <- get("plot", envir = asNamespace("base"))
} else {
plot <- get("plot", envir = asNamespace("graphics"))
}
plot(x = data$x,
y = data$s,
lwd = lwd,
@ -623,7 +625,7 @@ plot.rsi <- function(x,
barplot.rsi <- function(height,
col = c("chartreuse4", "chartreuse3", "brown3"),
xlab = ifelse(beside, "Antimicrobial Interpretation", ""),
main = paste("Antimicrobial resistance of", deparse(substitute(height))),
main = paste("Resistance Overview of", deparse(substitute(height))),
ylab = "Frequency",
beside = TRUE,
axes = beside,