diff --git a/DESCRIPTION b/DESCRIPTION index 05f2dc3a..ec0a79c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 1.5.0.9026 -Date: 2021-02-25 +Version: 1.5.0.9027 +Date: 2021-02-26 Title: Antimicrobial Resistance Data Analysis Authors@R: c( person(role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 7aaf7e1f..bcc131ca 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ -# AMR 1.5.0.9026 -## Last updated: 25 February 2021 +# AMR 1.5.0.9027 +## Last updated: 26 February 2021 ### New * Support for EUCAST Clinical Breakpoints v11.0 (2021), effective in the `eucast_rules()` function and in `as.rsi()` to interpret MIC and disk diffusion values. This is now the default guideline in this package. diff --git a/R/ggplot_rsi.R b/R/ggplot_rsi.R index 5de41893..b995d855 100755 --- a/R/ggplot_rsi.R +++ b/R/ggplot_rsi.R @@ -36,8 +36,8 @@ #' @param facet variable to split plots by, either `"interpretation"` (default) or `"antibiotic"` or a grouping variable #' @inheritParams proportion #' @param nrow (when using `facet`) number of rows -#' @param colours a named vector with colours for the bars. The names must be one or more of: S, SI, I, IR, R or be `FALSE` for standard [ggplot2][ggplot2::ggplot()] colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. -#' @param aesthetics aesthetics to apply the colours to, defaults to "fill" but can also be "colour" or "both" +#' @param colours a named vactor with colour to be used for filling. The default colours are colour-blind friendly. +#' @param aesthetics aesthetics to apply the colours to, defaults to "fill" but can also be (a combination of) "alpha", "colour", "fill", "linetype", "shape" or "size" #' @param datalabels show datalabels using [labels_rsi_count()] #' @param datalabels.size size of the datalabels #' @param datalabels.colour colour of the datalabels @@ -46,7 +46,7 @@ #' @param caption text to show as caption of the plot #' @param x.title text to show as x axis description #' @param y.title text to show as y axis description -#' @param ... other arguments passed on to [geom_rsi()] +#' @param ... other arguments passed on to [geom_rsi()] or, in case of [scale_rsi_colours()], named values to set colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. See *Examples*. #' @details At default, the names of antibiotics will be shown on the plots using [ab_name()]. This can be set with the `translate_ab` argument. See [count_df()]. #' #' ## The Functions @@ -56,7 +56,7 @@ #' #' [scale_y_percent()] transforms the y axis to a 0 to 100% range using [ggplot2::scale_y_continuous()]. #' -#' [scale_rsi_colours()] sets colours to the bars: pastel blue for S, pastel turquoise for I and pastel red for R, using [ggplot2::scale_fill_manual()]. +#' [scale_rsi_colours()] sets colours to the bars (green for S, yellow for I, and red for R). with multilingual support. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. #' #' [theme_rsi()] is a [ggplot2 theme][[ggplot2::theme()] with minimal distraction. #' @@ -219,11 +219,6 @@ ggplot_rsi <- function(data, theme_rsi() if (fill == "interpretation") { - # set RSI colours - if (isFALSE(colours) & missing(datalabels.colour)) { - # set datalabel colour to middle grey - datalabels.colour <- "grey50" - } p <- p + scale_rsi_colours(colours = colours) } @@ -362,28 +357,50 @@ scale_y_percent <- function(breaks = seq(0, 1, 0.1), limits = NULL) { #' @rdname ggplot_rsi #' @export -scale_rsi_colours <- function(colours = c(S = "#3CAEA3", - SI = "#3CAEA3", - I = "#F6D55C", - IR = "#ED553B", - R = "#ED553B"), +scale_rsi_colours <- function(..., aesthetics = "fill") { stop_ifnot_installed("ggplot2") - meet_criteria(colours, allow_class = c("character", "logical")) - meet_criteria(aesthetics, allow_class = c("character"), has_length = c(1, 2), is_in = c("colour", "color", "fill", "both")) + meet_criteria(aesthetics, allow_class = c("character"), has_length = c(1, 2), is_in = c("alpha", "colour", "color", "fill", "linetype", "shape", "size")) - if (!identical(colours, FALSE)) { - if ("both" %in% aesthetics) { - aesthetics <- c("colour", "fill") - } + # behaviour until AMR pkg v1.5.0 and also when coming from ggplot_rsi() + if ("colours" %in% names(list(...))) { original_cols <- c(S = "#3CAEA3", SI = "#3CAEA3", I = "#F6D55C", IR = "#ED553B", R = "#ED553B") - colours <- replace(original_cols, names(colours), colours) - ggplot2::scale_fill_manual(values = colours, aesthetics = aesthetics) + colours <- replace(original_cols, names(list(...)$colours), list(...)$colours) + return(ggplot2::scale_fill_manual(values = colours)) } + if (identical(unlist(list(...)), FALSE)) { + return(invisible()) + } + + names_susceptible <- c("S", "SI", "IS", "S+I", "I+S", "susceptible", + unique(translations_file[which(translations_file$pattern == "susceptible"), + "replacement", drop = TRUE])) + names_incr_exposure <- c("I", "intermediate", "increased exposure", "incr. exposure", + unique(translations_file[which(translations_file$pattern == "intermediate"), + "replacement", drop = TRUE])) + names_resistant <- c("R", "IR", "RI", "R+I", "I+R", "resistant", + unique(translations_file[which(translations_file$pattern == "resistant"), + "replacement", drop = TRUE])) + + susceptible <- rep("#3CAEA3", length(names_susceptible)) + names(susceptible) <- names_susceptible + incr_exposure <- rep("#F6D55C", length(names_incr_exposure)) + names(incr_exposure) <- names_incr_exposure + resistant <- rep("#ED553B", length(names_resistant)) + names(resistant) <- names_resistant + + original_cols = c(susceptible, incr_exposure, resistant) + dots <- c(...) + # replace S, I, R as colours: scale_rsi_colours(mydatavalue = "S") + dots[dots == "S"] <- "#3CAEA3" + dots[dots == "I"] <- "#F6D55C" + dots[dots == "R"] <- "#ED553B" + colours <- replace(original_cols, names(dots), dots) + ggplot2::scale_discrete_manual(aesthetics = aesthetics, values = colours) } #' @rdname ggplot_rsi diff --git a/R/plot.R b/R/plot.R index 39b4fe4d..ccc12ef6 100644 --- a/R/plot.R +++ b/R/plot.R @@ -50,9 +50,11 @@ #' @examples #' some_mic_values <- random_mic(size = 100) #' some_disk_values <- random_disk(size = 100, mo = "Escherichia coli", ab = "cipro") +#' some_rsi_values <- random_rsi(50, prob_RSI = c(0.30, 0.55, 0.05)) #' #' plot(some_mic_values) #' plot(some_disk_values) +#' plot(some_rsi_values) #' #' # when providing the microorganism and antibiotic, colours will show interpretations: #' plot(some_mic_values, mo = "S. aureus", ab = "ampicillin") @@ -61,6 +63,7 @@ #' if (require("ggplot2")) { #' ggplot(some_mic_values) #' ggplot(some_disk_values, mo = "Escherichia coli", ab = "cipro") +#' ggplot(some_rsi_values) #' } NULL @@ -229,7 +232,7 @@ ggplot.mic <- function(data, name = NULL) } else { p <- p + - ggplot2::geom_col(aes(x = mic, y = count)) + ggplot2::geom_col(ggplot2::aes(x = mic, y = count)) } p + @@ -242,7 +245,7 @@ ggplot.mic <- function(data, #' @importFrom graphics barplot axis mtext legend #' @rdname plot plot.disk <- function(x, - main = paste("Disk zones values of", deparse(substitute(x))), + main = paste("Disk zones of", deparse(substitute(x))), ylab = "Frequency", xlab = "Disk diffusion diameter (mm)", mo = NULL, @@ -315,7 +318,7 @@ plot.disk <- function(x, #' @export #' @noRd barplot.disk <- function(height, - main = paste("Disk zones values of", deparse(substitute(height))), + main = paste("Disk zones of", deparse(substitute(height))), ylab = "Frequency", xlab = "Disk diffusion diameter (mm)", mo = NULL, @@ -350,7 +353,7 @@ barplot.disk <- function(height, # will be exported using s3_register() in R/zzz.R ggplot.disk <- function(data, mapping = NULL, - title = paste("Disk zones values of", deparse(substitute(data))), + title = paste("Disk zones of", deparse(substitute(data))), ylab = "Frequency", xlab = "Disk diffusion diameter (mm)", mo = NULL, @@ -395,7 +398,7 @@ ggplot.disk <- function(data, if (any(colours_RSI %in% cols_sub$cols)) { p <- p + - ggplot2::geom_col(aes(x = disk, y = count, fill = cols)) + + ggplot2::geom_col(ggplot2::aes(x = disk, y = count, fill = cols)) + ggplot2::scale_fill_manual(values = c("Resistant" = colours_RSI[1], "Susceptible" = colours_RSI[2], "Incr. exposure" = colours_RSI[3], @@ -403,7 +406,7 @@ ggplot.disk <- function(data, name = NULL) } else { p <- p + - ggplot2::geom_col(aes(x = disk, y = count)) + ggplot2::geom_col(ggplot2::aes(x = disk, y = count)) } p + @@ -514,7 +517,7 @@ plot.rsi <- function(x, stringsAsFactors = FALSE) } - data$x <- factor(data$x, levels = c("R", "S", "I"), ordered = TRUE) + data$x <- factor(data$x, levels = c("S", "I", "R"), ordered = TRUE) ymax <- pm_if_else(max(data$s) > 95, 105, 100) @@ -558,7 +561,7 @@ barplot.rsi <- function(height, main <- gsub(" +", " ", paste0(main, collapse = " ")) x <- table(height) - x <- x[c(3, 1, 2)] + x <- x[c(1, 2, 3)] barplot(x, col = colours_RSI, xlab = xlab, @@ -567,3 +570,39 @@ barplot.rsi <- function(height, axes = FALSE) axis(2, seq(0, max(x))) } + +#' @method ggplot rsi +#' @rdname plot +# will be exported using s3_register() in R/zzz.R +ggplot.rsi <- function(data, + mapping = NULL, + title = paste("Resistance Overview of", deparse(substitute(data))), + xlab = "Antimicrobial Interpretation", + ylab = "Frequency", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + ...) { + stop_ifnot_installed("ggplot2") + meet_criteria(title, allow_class = "character") + meet_criteria(ylab, allow_class = "character", has_length = 1) + meet_criteria(xlab, allow_class = "character", has_length = 1) + meet_criteria(colours_RSI, allow_class = "character", has_length = c(1, 3)) + if (length(colours_RSI) == 1) { + colours_RSI <- rep(colours_RSI, 3) + } + + df <- as.data.frame(table(data), stringsAsFactors = TRUE) + colnames(df) <- c("rsi", "count") + if (!is.null(mapping)) { + p <- ggplot2::ggplot(df, mapping = mapping) + } else { + p <- ggplot2::ggplot(df) + } + + p + + ggplot2::geom_col(ggplot2::aes(x = rsi, y = count, fill = rsi)) + + ggplot2::scale_fill_manual(values = c("R" = colours_RSI[1], + "S" = colours_RSI[2], + "I" = colours_RSI[3])) + + ggplot2::labs(title = title, x = xlab, y = ylab) + + ggplot2::theme(legend.position = "none") +} diff --git a/R/zzz.R b/R/zzz.R index 4b02815b..0a6d3de9 100755 --- a/R/zzz.R +++ b/R/zzz.R @@ -50,6 +50,7 @@ pkg_env$mo_failed <- character(0) s3_register("skimr::get_skimmers", "rsi") s3_register("skimr::get_skimmers", "mic") s3_register("skimr::get_skimmers", "disk") + s3_register("ggplot2::ggplot", "rsi") s3_register("ggplot2::ggplot", "mic") s3_register("ggplot2::ggplot", "disk") diff --git a/data-raw/AMR_latest.tar.gz b/data-raw/AMR_latest.tar.gz index 4dd2b077..eca1b5a3 100644 Binary files a/data-raw/AMR_latest.tar.gz and b/data-raw/AMR_latest.tar.gz differ diff --git a/docs/404.html b/docs/404.html index e711daef..4fd98338 100644 --- a/docs/404.html +++ b/docs/404.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027 diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index f67dc4fb..1a9ba51a 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027 diff --git a/docs/articles/AMR.html b/docs/articles/AMR.html index 36c71043..6b438568 100644 --- a/docs/articles/AMR.html +++ b/docs/articles/AMR.html @@ -39,7 +39,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027 @@ -193,7 +193,7 @@

How to conduct AMR data analysis

Matthijs S. Berends

-

25 February 2021

+

26 February 2021

Source: vignettes/AMR.Rmd @@ -202,7 +202,7 @@ -

Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 25 February 2021.

+

Note: values on this page will change with every website update since they are based on randomly created values and the page was written in R Markdown. However, the methodology remains unchanged. This page was generated on 26 February 2021.

Introduction

@@ -233,21 +233,21 @@ -2021-02-25 +2021-02-26 abcd Escherichia coli S S -2021-02-25 +2021-02-26 abcd Escherichia coli S R -2021-02-25 +2021-02-26 efgh Escherichia coli R @@ -344,10 +344,32 @@ -2014-07-28 -B5 +2012-05-31 +J3 Hospital A Escherichia coli +R +I +S +S +M + + +2012-11-27 +R2 +Hospital B +Klebsiella pneumoniae +S +S +R +S +F + + +2017-07-10 +B1 +Hospital B +Streptococcus pneumoniae S S S @@ -355,54 +377,32 @@ M -2017-09-25 -X1 +2013-11-18 +B1 Hospital B Klebsiella pneumoniae +S +R R -I S -S -F +M -2017-04-18 -V9 -Hospital D -Klebsiella pneumoniae -I -S -S -S -F - - -2016-06-06 -Z2 +2016-07-29 +O3 Hospital A -Staphylococcus aureus +Streptococcus pneumoniae R S S S F - -2016-01-08 -V6 -Hospital C -Klebsiella pneumoniae -S -S -S -S -F - -2015-03-14 -Y2 +2016-09-06 +U3 Hospital B -Staphylococcus aureus +Streptococcus pneumoniae S S S @@ -441,16 +441,16 @@ Longest: 1

1 M -10,502 -52.51% -10,502 -52.51% +10,409 +52.05% +10,409 +52.05% 2 F -9,498 -47.49% +9,591 +47.96% 20,000 100.00% @@ -495,7 +495,7 @@ Longest: 1

# NOTE: Using column 'bacteria' as input for `col_mo`. # NOTE: Using column 'date' as input for `col_date`. # NOTE: Using column 'patient_id' as input for `col_patient_id`.
-

So only 28.3% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

+

So only 28.4% is suitable for resistance analysis! We can now filter on it with the filter() function, also from the dplyr package:

 data_1st <- data %>% 
   filter(first == TRUE)
@@ -507,7 +507,7 @@ Longest: 1

First weighted isolates

-

We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all E. coli isolates of patient B7, sorted on date:

+

We made a slight twist to the CLSI algorithm, to take into account the antimicrobial susceptibility profile. Have a look at all E. coli isolates of patient Y5, sorted on date:

@@ -523,10 +523,10 @@ Longest: 1

- - + + - + @@ -534,8 +534,8 @@ Longest: 1

- - + + @@ -545,19 +545,19 @@ Longest: 1

- - + + + + - - - - + + @@ -567,19 +567,19 @@ Longest: 1

- - + + - - - + + + - - + + @@ -589,10 +589,10 @@ Longest: 1

- - + + - + @@ -600,33 +600,33 @@ Longest: 1

- - + + - - + + - - + + - - - + + + - - + + - - + + @@ -657,10 +657,10 @@ Longest: 1

- - + + - + @@ -669,8 +669,8 @@ Longest: 1

- - + + @@ -681,20 +681,20 @@ Longest: 1

- - + + + + - - - + - - + + @@ -705,47 +705,47 @@ Longest: 1

- - + + - - - + + + + - - - + + - + - - + + - + - + - - + + - - + + @@ -753,36 +753,36 @@ Longest: 1

- - + + - - - + + + - - + + - - + + - +
isolate
12010-03-16B72010-01-04Y5 B_ESCHR_COLIRS S S S
22010-05-03B72010-01-13Y5 B_ESCHR_COLI S S
32010-05-16B72010-04-23Y5 B_ESCHR_COLISS R SSS FALSE
42010-07-25B72010-06-13Y5 B_ESCHR_COLI S S
52010-07-26B72010-09-02Y5 B_ESCHR_COLIRR SRSSS FALSE
62010-10-14B72010-11-12Y5 B_ESCHR_COLI S S
72010-12-24B72010-11-14Y5 B_ESCHR_COLIRS S S S
82011-02-27B72010-12-31Y5 B_ESCHR_COLISSRR S S FALSE
92011-09-02B72011-03-02Y5 B_ESCHR_COLISSS RRSS TRUE
102011-11-08B72011-06-09Y5 B_ESCHR_COLIIIRR S S FALSE
12010-03-16B72010-01-04Y5 B_ESCHR_COLIRS S S S
22010-05-03B72010-01-13Y5 B_ESCHR_COLI S S
32010-05-16B72010-04-23Y5 B_ESCHR_COLISS R SSS FALSETRUEFALSE
42010-07-25B72010-06-13Y5 B_ESCHR_COLI S S
52010-07-26B72010-09-02Y5 B_ESCHR_COLIRR SRSSSFALSE FALSETRUE
62010-10-14B72010-11-12Y5 B_ESCHR_COLI S S S S FALSETRUEFALSE
72010-12-24B72010-11-14Y5 B_ESCHR_COLIRS S S S FALSETRUEFALSE
82011-02-27B72010-12-31Y5 B_ESCHR_COLISSRR S S FALSE
92011-09-02B72011-03-02Y5 B_ESCHR_COLISSS RRSS TRUE TRUE
102011-11-08B72011-06-09Y5 B_ESCHR_COLIIIRR S S FALSETRUEFALSE
-

Instead of 2, now 10 isolates are flagged. In total, 79.1% of all isolates are marked ‘first weighted’ - 50.8% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

+

Instead of 2, now 5 isolates are flagged. In total, 78.5% of all isolates are marked ‘first weighted’ - 50.1% more than when using the CLSI guideline. In real life, this novel algorithm will yield 5-10% more isolates than the classic CLSI guideline.

As with filter_first_isolate(), there’s a shortcut for this new algorithm too:

 data_1st <- data %>% 
   filter_first_weighted_isolate()
-

So we end up with 15,821 isolates for analysis.

+

So we end up with 15,695 isolates for analysis.

We can remove unneeded columns:

 data_1st <- data_1st %>% 
@@ -792,7 +792,6 @@ Longest: 1

head(data_1st)
-@@ -802,13 +801,12 @@ Longest: 1

-+ - @@ -825,13 +823,12 @@ Longest: 1

- - - + + - - + + @@ -841,14 +838,13 @@ Longest: 1

- - - + + - + @@ -857,67 +853,63 @@ Longest: 1

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -941,8 +933,8 @@ Longest: 1

data_1st %>% freq(genus, species)

Frequency table

Class: character
-Length: 15,821
-Available: 15,821 (100%, NA: 0 = 0%)
+Length: 15,695
+Available: 15,695 (100%, NA: 0 = 0%)
Unique: 4

Shortest: 16
Longest: 24

@@ -959,33 +951,33 @@ Longest: 24

- - - - + + + + - - - + + + - - - - + + + + - - - + + + @@ -1012,50 +1004,50 @@ Longest: 24

- - - - + + + + - - - - + + + + - + - - + + - + - - + + - - + + - - - - + + + +
date patient_id hospital
12014-07-28B52012-05-31J3 Hospital A B_ESCHR_COLISSRI S S M TRUE
22017-09-25X12012-11-27R2 Hospital B B_KLBSL_PNMN RI SR S F Gram-negative TRUE
32017-04-18V9Hospital DB_KLBSL_PNMNRSSSFGram-negativeKlebsiellapneumoniaeTRUE
52016-01-08V6Hospital CB_KLBSL_PNMNRSSSFGram-negativeKlebsiellapneumoniaeTRUE
62015-03-14Y22017-07-10B1 Hospital BB_STPHY_AURSSSSSFGram-positiveStaphylococcusaureusTRUE
72014-12-23G8Hospital AB_STPHY_AURSSB_STRPT_PNMN S S SR M Gram-positiveStaphylococcusaureusStreptococcuspneumoniaeTRUE
2013-11-18B1Hospital BB_KLBSL_PNMNRRRSMGram-negativeKlebsiellapneumoniaeTRUE
2016-07-29O3Hospital AB_STRPT_PNMNRRSRFGram-positiveStreptococcuspneumoniaeTRUE
2016-09-06U3Hospital BB_STRPT_PNMNSSSRFGram-positiveStreptococcuspneumoniae TRUE
1 Escherichia coli7,99450.53%7,99450.53%7,82949.88%7,82949.88%
2 Staphylococcus aureus3,92324.80%11,9173,99225.43%11,821 75.32%
3 Streptococcus pneumoniae2,32114.67%14,23889.99%2,28714.57%14,10889.89%
4 Klebsiella pneumoniae1,58310.01%15,8211,58710.11%15,695 100.00%
E. coli AMX381523939407994374323138557829
E. coli AMC628930414017994620028313467829
E. coli CIP60865941 01908799418887829
E. coli GEN71587047 083679947827829
K. pneumoniae AMX 0 01583158315871587
K. pneumoniae AMC12245730215831242652801587
@@ -1078,34 +1070,34 @@ Longest: 24

E. coli CIP -6086 +5941 0 -1908 -7994 +1888 +7829 K. pneumoniae CIP -1215 +1218 0 -368 -1583 +369 +1587 S. aureus CIP -3062 +3099 0 -861 -3923 +893 +3992 S. pneumoniae CIP -1765 +1783 0 -556 -2321 +504 +2287 @@ -1118,7 +1110,7 @@ Longest: 24

As per the EUCAST guideline of 2019, we calculate resistance as the proportion of R (proportion_R(), equal to resistance()) and susceptibility as the proportion of S and I (proportion_SI(), equal to susceptibility()). These functions can be used on their own:

 data_1st %>% resistance(AMX)
-# [1] 0.5370078
+# [1] 0.5413189

Or can be used in conjuction with group_by() and summarise(), both from the dplyr package:

 data_1st %>% 
@@ -1133,19 +1125,19 @@ Longest: 24

Hospital A -0.5410321 +0.5453191 Hospital B -0.5381272 +0.5342294 Hospital C -0.5306981 +0.5395015 Hospital D -0.5338134 +0.5495407 @@ -1165,23 +1157,23 @@ Longest: 24

Hospital A -0.5410321 -4728 +0.5453191 +4700 Hospital B -0.5381272 -5521 +0.5342294 +5580 Hospital C -0.5306981 -2378 +0.5395015 +2367 Hospital D -0.5338134 -3194 +0.5495407 +3048 @@ -1203,27 +1195,27 @@ Longest: 24

Escherichia -0.8247436 -0.8954216 -0.9836127 +0.8280751 +0.9001150 +0.9840337 Klebsiella -0.8092230 -0.9001895 -0.9823121 +0.8235665 +0.8890989 +0.9823566 Staphylococcus -0.8179964 -0.9166454 -0.9836860 +0.8274048 +0.9251002 +0.9874749 Streptococcus -0.5489013 +0.5347617 0.0000000 -0.5489013 +0.5347617 @@ -1308,62 +1300,59 @@ Longest: 24

mic_values <- random_mic(size = 100) mic_values # Class <mic> -# [1] 128 64 0.5 8 64 0.125 16 64 8 2 -# [11] 0.0625 8 1 4 0.25 0.5 0.5 32 1 1 -# [21] 0.25 8 8 0.0625 16 16 2 64 0.125 8 -# [31] 1 0.125 4 0.125 32 16 0.25 1 0.5 128 -# [41] 32 128 64 1 0.125 32 0.125 0.125 8 0.125 -# [51] 64 8 8 0.0625 0.25 0.5 2 2 128 0.25 -# [61] 4 1 1 0.25 64 0.5 32 0.25 16 2 -# [71] 16 8 32 4 0.25 16 128 32 128 4 -# [81] 64 1 0.25 0.5 1 1 4 8 16 16 -# [91] 32 0.5 1 0.125 2 128 0.5 1 4 64
+# [1] 16 1 0.125 0.5 2 0.25 0.5 0.25 0.25 128 +# [11] 1 0.125 8 128 16 256 2 0.25 256 2 +# [21] 2 0.25 0.0625 1 8 2 1 2 32 128 +# [31] 4 0.125 4 0.5 32 0.125 0.25 16 0.5 128 +# [41] 0.0625 8 0.125 0.25 256 0.125 0.5 1 32 64 +# [51] 0.5 1 16 1 256 0.125 8 64 0.5 1 +# [61] 0.25 64 256 128 0.25 64 2 4 8 2 +# [71] 4 1 32 64 64 256 0.5 0.0625 1 256 +# [81] 8 32 64 0.125 32 4 8 0.125 4 0.25 +# [91] 64 4 64 128 16 0.0625 2 256 4 0.0625
 # base R:
 plot(mic_values)
-

+

 # ggplot2:
 ggplot(mic_values)
-

+

But we could also be more specific, by generating MICs that are likely to be found in E. coli for ciprofloxacin:

-# this will generate MICs that are likely to be found in E. coli for ciprofloxacin:
-mic_values_specific <- random_mic(size = 100, mo = "E. coli", ab = "cipro")
+mic_values <- random_mic(size = 100, mo = "E. coli", ab = "cipro")

For the plot() and ggplot() function, we can define the microorganism and an antimicrobial agent the same way. This will add the interpretation of those values according to a chosen guidelines (defaults to the latest EUCAST guideline).

Default colours are colour-blind friendly, while maintaining the convention that e.g. ‘susceptible’ should be green and ‘resistant’ should be red:

 # base R:
-plot(mic_values_specific, mo = "E. coli", ab = "cipro")
-

+plot(mic_values, mo = "E. coli", ab = "cipro") +

 # ggplot2:
-ggplot(mic_values_specific, mo = "E. coli", ab = "cipro")
-

+ggplot(mic_values, mo = "E. coli", ab = "cipro") +

For disk diffusion values, there is not much of a difference in plotting:

-# this will generate disks that are likely to be found in E. coli for ciprofloxacin:
-disk_values_specific <- random_disk(size = 100, mo = "E. coli", ab = "cipro")
+disk_values <- random_disk(size = 100, mo = "E. coli", ab = "cipro")
 # NOTE: Translation to one microorganism was guessed with uncertainty. Use
 #       `mo_uncertainties()` to review it.
-disk_values_specific
+disk_values
 # Class <disk>
-#   [1] 20 29 20 26 27 22 18 21 29 23 18 19 29 26 27 24 20 20 23 20 18 25 31 31 29
-#  [26] 28 27 31 18 21 18 26 30 20 21 27 24 27 19 24 17 26 24 31 30 28 19 30 19 21
-#  [51] 17 19 22 19 23 23 19 20 28 31 31 30 20 17 21 31 29 29 27 21 29 27 26 18 21
-#  [76] 29 21 26 29 22 24 18 22 29 30 17 19 23 26 31 17 18 18 28 30 25 22 21 27 17
+# [1] 24 28 21 23 26 26 24 26 29 20 19 29 24 19 18 18 18 18 31 21 27 31 28 23 19 +# [26] 22 30 19 20 30 30 27 31 30 20 22 28 17 17 19 23 23 24 23 29 29 19 29 29 17 +# [51] 24 27 19 23 19 31 24 22 25 21 27 30 26 17 21 22 25 18 30 19 18 29 27 20 26 +# [76] 20 31 18 19 26 31 17 26 25 17 20 28 18 28 17 21 17 17 20 28 26 19 28 19 18
 # base R:
-plot(disk_values_specific, mo = "E. coli", ab = "cipro")
-

+plot(disk_values, mo = "E. coli", ab = "cipro") +

And when using the ggplot2 package, but now choosing the latest implemented CLSI guideline (notice that the EUCAST-specific term “Incr. exposure” has changed to “Intermediate”):

-# and ggplot2, but now choosing an old CLSI guideline:
-ggplot(disk_values_specific,
+ggplot(disk_values,
        mo = "E. coli",
        ab = "cipro",
        guideline = "CLSI")
-

+

diff --git a/docs/articles/AMR_files/figure-html/disk_plots-1.png b/docs/articles/AMR_files/figure-html/disk_plots-1.png new file mode 100644 index 00000000..606ad5d0 Binary files /dev/null and b/docs/articles/AMR_files/figure-html/disk_plots-1.png differ diff --git a/docs/articles/AMR_files/figure-html/disk_plots_mo_ab-1.png b/docs/articles/AMR_files/figure-html/disk_plots_mo_ab-1.png new file mode 100644 index 00000000..ec78c6b9 Binary files /dev/null and b/docs/articles/AMR_files/figure-html/disk_plots_mo_ab-1.png differ diff --git a/docs/articles/AMR_files/figure-html/mic_plots-1.png b/docs/articles/AMR_files/figure-html/mic_plots-1.png new file mode 100644 index 00000000..c0c405b1 Binary files /dev/null and b/docs/articles/AMR_files/figure-html/mic_plots-1.png differ diff --git a/docs/articles/AMR_files/figure-html/mic_plots-2.png b/docs/articles/AMR_files/figure-html/mic_plots-2.png new file mode 100644 index 00000000..ba45698c Binary files /dev/null and b/docs/articles/AMR_files/figure-html/mic_plots-2.png differ diff --git a/docs/articles/AMR_files/figure-html/mic_plots_mo_ab-1.png b/docs/articles/AMR_files/figure-html/mic_plots_mo_ab-1.png new file mode 100644 index 00000000..616503d5 Binary files /dev/null and b/docs/articles/AMR_files/figure-html/mic_plots_mo_ab-1.png differ diff --git a/docs/articles/AMR_files/figure-html/mic_plots_mo_ab-2.png b/docs/articles/AMR_files/figure-html/mic_plots_mo_ab-2.png new file mode 100644 index 00000000..3f1c03e0 Binary files /dev/null and b/docs/articles/AMR_files/figure-html/mic_plots_mo_ab-2.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 1-1.png b/docs/articles/AMR_files/figure-html/plot 1-1.png index 29ba2535..91dd3872 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 1-1.png and b/docs/articles/AMR_files/figure-html/plot 1-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 3-1.png b/docs/articles/AMR_files/figure-html/plot 3-1.png index ab08612c..45df6627 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 3-1.png and b/docs/articles/AMR_files/figure-html/plot 3-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 4-1.png b/docs/articles/AMR_files/figure-html/plot 4-1.png index 76f329c0..ab05102e 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 4-1.png and b/docs/articles/AMR_files/figure-html/plot 4-1.png differ diff --git a/docs/articles/AMR_files/figure-html/plot 5-1.png b/docs/articles/AMR_files/figure-html/plot 5-1.png index 83c570d7..a6d8ac09 100644 Binary files a/docs/articles/AMR_files/figure-html/plot 5-1.png and b/docs/articles/AMR_files/figure-html/plot 5-1.png differ diff --git a/docs/articles/AMR_files/figure-html/unnamed-chunk-13-1.png b/docs/articles/AMR_files/figure-html/unnamed-chunk-13-1.png deleted file mode 100644 index 7f506b40..00000000 Binary files a/docs/articles/AMR_files/figure-html/unnamed-chunk-13-1.png and /dev/null differ diff --git a/docs/articles/AMR_files/figure-html/unnamed-chunk-13-2.png b/docs/articles/AMR_files/figure-html/unnamed-chunk-13-2.png deleted file mode 100644 index 61f95564..00000000 Binary files a/docs/articles/AMR_files/figure-html/unnamed-chunk-13-2.png and /dev/null differ diff --git a/docs/articles/AMR_files/figure-html/unnamed-chunk-15-1.png b/docs/articles/AMR_files/figure-html/unnamed-chunk-15-1.png deleted file mode 100644 index a7c32bcd..00000000 Binary files a/docs/articles/AMR_files/figure-html/unnamed-chunk-15-1.png and /dev/null differ diff --git a/docs/articles/AMR_files/figure-html/unnamed-chunk-15-2.png b/docs/articles/AMR_files/figure-html/unnamed-chunk-15-2.png deleted file mode 100644 index 7c46433a..00000000 Binary files a/docs/articles/AMR_files/figure-html/unnamed-chunk-15-2.png and /dev/null differ diff --git a/docs/articles/AMR_files/figure-html/unnamed-chunk-17-1.png b/docs/articles/AMR_files/figure-html/unnamed-chunk-17-1.png deleted file mode 100644 index 1d0c5d57..00000000 Binary files a/docs/articles/AMR_files/figure-html/unnamed-chunk-17-1.png and /dev/null differ diff --git a/docs/articles/AMR_files/figure-html/unnamed-chunk-18-1.png b/docs/articles/AMR_files/figure-html/unnamed-chunk-18-1.png deleted file mode 100644 index 6cd717bc..00000000 Binary files a/docs/articles/AMR_files/figure-html/unnamed-chunk-18-1.png and /dev/null differ diff --git a/docs/articles/benchmarks.html b/docs/articles/benchmarks.html index 2c1bf65b..9f4c250f 100644 --- a/docs/articles/benchmarks.html +++ b/docs/articles/benchmarks.html @@ -39,7 +39,7 @@ AMR (for R) - 1.5.0.9025 + 1.5.0.9027
@@ -226,19 +226,19 @@ times = 25) print(S.aureus, unit = "ms", signif = 2) # Unit: milliseconds -# expr min lq mean median uq max neval -# as.mo("sau") 10 11.0 15 11.0 13.0 47 25 -# as.mo("stau") 56 57.0 75 62.0 95.0 100 25 -# as.mo("STAU") 54 56.0 67 58.0 66.0 110 25 -# as.mo("staaur") 10 11.0 12 11.0 12.0 13 25 -# as.mo("STAAUR") 10 11.0 16 11.0 12.0 50 25 -# as.mo("S. aureus") 28 31.0 46 33.0 65.0 71 25 -# as.mo("S aureus") 29 30.0 42 33.0 64.0 67 25 -# as.mo("Staphylococcus aureus") 3 3.2 5 3.3 3.7 40 25 -# as.mo("Staphylococcus aureus (MRSA)") 240 260.0 270 270.0 280.0 290 25 -# as.mo("Sthafilokkockus aaureuz") 170 200.0 210 200.0 210.0 280 25 -# as.mo("MRSA") 10 11.0 17 11.0 13.0 51 25 -# as.mo("VISA") 19 20.0 36 21.0 50.0 150 25
+# expr min lq mean median uq max neval +# as.mo("sau") 9.9 11.0 13.0 11.0 12.0 43 25 +# as.mo("stau") 52.0 55.0 68.0 58.0 86.0 95 25 +# as.mo("STAU") 53.0 56.0 73.0 62.0 93.0 100 25 +# as.mo("staaur") 10.0 11.0 17.0 11.0 12.0 48 25 +# as.mo("STAAUR") 10.0 11.0 14.0 11.0 13.0 48 25 +# as.mo("S. aureus") 27.0 28.0 41.0 33.0 60.0 73 25 +# as.mo("S aureus") 27.0 28.0 49.0 34.0 64.0 160 25 +# as.mo("Staphylococcus aureus") 2.9 3.2 4.8 3.4 3.7 36 25 +# as.mo("Staphylococcus aureus (MRSA)") 250.0 260.0 270.0 270.0 280.0 320 25 +# as.mo("Sthafilokkockus aaureuz") 170.0 200.0 210.0 210.0 210.0 310 25 +# as.mo("MRSA") 10.0 11.0 16.0 12.0 12.0 50 25 +# as.mo("VISA") 19.0 20.0 27.0 21.0 23.0 60 25

In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 200 milliseconds, this is only 5 input values per second. It is clear that accepted taxonomic names are extremely fast, but some variations are up to 200 times slower to determine.

To improve performance, we implemented two important algorithms to save unnecessary calculations: repetitive results and already precalculated results.

@@ -260,8 +260,8 @@ # what do these values look like? They are of class <mo>: head(x) # Class <mo> -# [1] B_ESCHR_COLI B_PROTS_MRBL B_PROTS_MRBL B_PROTS_MRBL B_STPHY_CONS -# [6] B_ENTRC +# [1] B_STRPT_PYGN B_STPHY_HMNS B_STPHY_CONS B_STRPT_SLVR B_ENTRBC_CLOC +# [6] B_STPHY_CONS # as the example_isolates data set has 2,000 rows, we should have 2 million items length(x) @@ -277,8 +277,8 @@ print(run_it, unit = "ms", signif = 3) # Unit: milliseconds # expr min lq mean median uq max neval -# mo_name(x) 160 189 224 201 228 356 10 -

So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.201 seconds. That is 101 nanoseconds on average. You only lose time on your unique input values.

+# mo_name(x) 161 194 224 204 229 368 10 +

So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.204 seconds. That is 102 nanoseconds on average. You only lose time on your unique input values.

@@ -291,10 +291,10 @@ times = 10) print(run_it, unit = "ms", signif = 3) # Unit: milliseconds -# expr min lq mean median uq max neval -# A 6.80 7.17 7.46 7.54 7.81 8.0 10 -# B 24.30 25.80 31.60 26.20 28.80 75.6 10 -# C 1.59 1.70 1.89 1.84 2.02 2.5 10

+# expr min lq mean median uq max neval +# A 7.45 7.84 12.70 8.62 9.16 51.10 10 +# B 23.80 24.50 30.60 26.30 28.80 70.20 10 +# C 1.66 1.74 1.85 1.79 1.92 2.24 10

So going from mo_name("Staphylococcus aureus") to "Staphylococcus aureus" takes 0.0018 seconds - it doesn’t even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:

 run_it <- microbenchmark(A = mo_species("aureus"),
@@ -309,14 +309,14 @@
 print(run_it, unit = "ms", signif = 3)
 # Unit: milliseconds
 #  expr  min   lq mean median   uq  max neval
-#     A 1.25 1.28 1.39   1.39 1.50 1.56    10
-#     B 1.17 1.19 1.41   1.43 1.48 1.92    10
-#     C 1.20 1.33 1.43   1.46 1.50 1.61    10
-#     D 1.43 1.45 1.50   1.49 1.53 1.61    10
-#     E 1.26 1.40 1.45   1.43 1.49 1.81    10
-#     F 1.15 1.17 1.32   1.26 1.44 1.69    10
-#     G 1.19 1.25 1.37   1.35 1.47 1.58    10
-#     H 1.20 1.25 1.46   1.31 1.53 2.33    10
+# A 1.59 1.60 1.91 1.97 2.15 2.28 10 +# B 1.58 1.61 1.87 1.86 1.96 2.39 10 +# C 1.55 1.57 1.64 1.63 1.69 1.79 10 +# D 1.57 1.60 1.83 1.72 1.92 2.73 10 +# E 1.50 1.74 1.86 1.86 2.03 2.24 10 +# F 1.49 1.55 1.75 1.67 1.90 2.24 10 +# G 1.54 1.59 1.69 1.65 1.77 1.95 10 +# H 1.57 1.58 1.75 1.72 1.78 2.21 10

Of course, when running mo_phylum("Firmicutes") the function has zero knowledge about the actual microorganism, namely S. aureus. But since the result would be "Firmicutes" anyway, there is no point in calculating the result. And because this package contains all phyla of all known bacteria, it can just return the initial value immediately.

@@ -343,14 +343,14 @@ times = 100) print(run_it, unit = "ms", signif = 4) # Unit: milliseconds -# expr min lq mean median uq max neval -# en 17.05 17.38 21.26 17.74 18.50 97.23 100 -# de 19.90 20.33 24.80 20.67 21.06 93.34 100 -# nl 24.86 25.30 31.21 25.65 26.34 102.20 100 -# es 19.83 20.22 26.56 20.49 21.20 97.59 100 -# it 19.79 20.20 26.82 20.63 21.31 94.85 100 -# fr 19.61 19.87 24.26 20.21 20.68 92.42 100 -# pt 19.64 20.06 23.78 20.40 21.05 92.91 100
+# expr min lq mean median uq max neval +# en 17.33 18.21 21.97 19.06 20.40 68.32 100 +# de 20.44 21.37 30.49 22.33 24.97 78.42 100 +# nl 25.13 26.10 31.91 27.11 28.50 86.00 100 +# es 20.28 21.16 26.37 22.03 23.67 74.74 100 +# it 20.06 21.00 26.05 21.95 23.42 94.16 100 +# fr 19.90 20.63 24.40 21.85 22.82 69.07 100 +# pt 20.22 21.03 25.63 21.89 23.24 76.63 100

Currently supported non-English languages are German, Dutch, Spanish, Italian, French and Portuguese.

diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png index 71a7c0cf..766c4fa4 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index af4e1b72..bced51df 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027 diff --git a/docs/authors.html b/docs/authors.html index 3e35632f..494c82ae 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027 diff --git a/docs/extra.css b/docs/extra.css index a0e2a435..093e035c 100644 --- a/docs/extra.css +++ b/docs/extra.css @@ -207,10 +207,11 @@ div[id^=last-updated] h2 { .table thead th { text-align: inherit; } -.table a:not(.btn) { +/* all tables, including argument lists */ +table a:not(.btn) { text-decoration: inherit; } -.table a:not(.btn):hover { +table a:not(.btn):hover { text-decoration: underline; } diff --git a/docs/index.html b/docs/index.html index 43bfb2c4..cc41dfe0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027 diff --git a/docs/news/index.html b/docs/news/index.html index eaa4cff7..72fb87a8 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027 @@ -236,13 +236,13 @@ Source: NEWS.md -
-

-AMR 1.5.0.9026 Unreleased +
+

+AMR 1.5.0.9027 Unreleased

-
+

-Last updated: 25 February 2021 +Last updated: 26 February 2021

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 6e8c2411..574b64d8 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -12,7 +12,7 @@ articles: datasets: datasets.html resistance_predict: resistance_predict.html welcome_to_AMR: welcome_to_AMR.html -last_built: 2021-02-25T11:30Z +last_built: 2021-02-26T11:10Z urls: reference: https://msberends.github.io/AMR//reference article: https://msberends.github.io/AMR//articles diff --git a/docs/reference/as.mic.html b/docs/reference/as.mic.html index 2f6578da..60f5f68e 100644 --- a/docs/reference/as.mic.html +++ b/docs/reference/as.mic.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9025 + 1.5.0.9027

diff --git a/docs/reference/ggplot_rsi.html b/docs/reference/ggplot_rsi.html index 22a4efab..1a7b4480 100644 --- a/docs/reference/ggplot_rsi.html +++ b/docs/reference/ggplot_rsi.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027
@@ -285,11 +285,7 @@ scale_y_percent(breaks = seq(0, 1, 0.1), limits = NULL) -scale_rsi_colours( - colours = c(S = "#3CAEA3", SI = "#3CAEA3", I = "#F6D55C", IR = "#ED553B", R = - "#ED553B"), - aesthetics = "fill" -) +scale_rsi_colours(..., aesthetics = "fill") theme_rsi() @@ -362,7 +358,7 @@ colours -

a named vector with colours for the bars. The names must be one or more of: S, SI, I, IR, R or be FALSE for standard ggplot2 colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red.

+

a named vactor with colour to be used for filling. The default colours are colour-blind friendly.

datalabels @@ -398,11 +394,11 @@ ... -

other arguments passed on to geom_rsi()

+

other arguments passed on to geom_rsi() or, in case of scale_rsi_colours(), named values to set colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. See Examples.

aesthetics -

aesthetics to apply the colours to, defaults to "fill" but can also be "colour" or "both"

+

aesthetics to apply the colours to, defaults to "fill" but can also be (a combination of) "alpha", "colour", "fill", "linetype", "shape" or "size"

@@ -414,7 +410,7 @@

geom_rsi() will take any variable from the data that has an rsi class (created with as.rsi()) using rsi_df() and will plot bars with the percentage R, I and S. The default behaviour is to have the bars stacked and to have the different antibiotics on the x axis.

facet_rsi() creates 2d plots (at default based on S/I/R) using ggplot2::facet_wrap().

scale_y_percent() transforms the y axis to a 0 to 100% range using ggplot2::scale_y_continuous().

-

scale_rsi_colours() sets colours to the bars: pastel blue for S, pastel turquoise for I and pastel red for R, using ggplot2::scale_fill_manual().

+

scale_rsi_colours() sets colours to the bars (green for S, yellow for I, and red for R). with multilingual support. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red.

theme_rsi() is a [ggplot2 theme][ggplot2::theme() with minimal distraction.

labels_rsi_count() print datalabels on the bars with percentage and amount of isolates using ggplot2::geom_text().

ggplot_rsi() is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (%>%). See Examples.

diff --git a/docs/reference/index.html b/docs/reference/index.html index 1009a227..67668ddb 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027
@@ -453,7 +453,7 @@ -

plot(<mic>) ggplot(<mic>) plot(<disk>) ggplot(<disk>) plot(<rsi>)

+

plot(<mic>) ggplot(<mic>) plot(<disk>) ggplot(<disk>) plot(<rsi>) ggplot(<rsi>)

Plotting for Classes rsi, mic and disk

diff --git a/docs/reference/like.html b/docs/reference/like.html index cfcb4f03..eabe55d5 100644 --- a/docs/reference/like.html +++ b/docs/reference/like.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9025 + 1.5.0.9027
diff --git a/docs/reference/plot.html b/docs/reference/plot.html index f5a0f234..a906f97e 100644 --- a/docs/reference/plot.html +++ b/docs/reference/plot.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027

@@ -274,7 +274,7 @@ # S3 method for disk plot( x, - main = paste("Disk zones values of", deparse(substitute(x))), + main = paste("Disk zones of", deparse(substitute(x))), ylab = "Frequency", xlab = "Disk diffusion diameter (mm)", mo = NULL, @@ -289,7 +289,7 @@ ggplot( data, mapping = NULL, - title = paste("Disk zones values of", deparse(substitute(data))), + title = paste("Disk zones of", deparse(substitute(data))), ylab = "Frequency", xlab = "Disk diffusion diameter (mm)", mo = NULL, @@ -307,6 +307,17 @@ xlab = "Antimicrobial Interpretation", main = paste("Resistance Overview of", deparse(substitute(x))), ... +) + +# S3 method for rsi +ggplot( + data, + mapping = NULL, + title = paste("Resistance Overview of", deparse(substitute(data))), + xlab = "Antimicrobial Interpretation", + ylab = "Frequency", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + ... )

Arguments

@@ -378,9 +389,11 @@ The lifecycle of this function is stableExamples
some_mic_values <- random_mic(size = 100)
 some_disk_values <- random_disk(size = 100, mo = "Escherichia coli", ab = "cipro")
+some_rsi_values <- random_rsi(50, prob_RSI = c(0.30, 0.55, 0.05))
 
 plot(some_mic_values)
 plot(some_disk_values)
+plot(some_rsi_values)
 
 # when providing the microorganism and antibiotic, colours will show interpretations:
 plot(some_mic_values, mo = "S. aureus", ab = "ampicillin")
@@ -389,6 +402,7 @@ The lifecycle of this function is stableif (require("ggplot2")) {
   ggplot(some_mic_values)
   ggplot(some_disk_values, mo = "Escherichia coli", ab = "cipro")
+  ggplot(some_rsi_values)
 }
 
diff --git a/docs/reference/random.html b/docs/reference/random.html index 3f67558d..fabdb0a0 100644 --- a/docs/reference/random.html +++ b/docs/reference/random.html @@ -82,7 +82,7 @@ AMR (for R) - 1.5.0.9025 + 1.5.0.9027 diff --git a/docs/survey.html b/docs/survey.html index 87e4af3a..1d89b89d 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ AMR (for R) - 1.5.0.9026 + 1.5.0.9027 diff --git a/man/ggplot_rsi.Rd b/man/ggplot_rsi.Rd index 1cc70659..797b5a17 100644 --- a/man/ggplot_rsi.Rd +++ b/man/ggplot_rsi.Rd @@ -53,11 +53,7 @@ facet_rsi(facet = c("interpretation", "antibiotic"), nrow = NULL) scale_y_percent(breaks = seq(0, 1, 0.1), limits = NULL) -scale_rsi_colours( - colours = c(S = "#3CAEA3", SI = "#3CAEA3", I = "#F6D55C", IR = "#ED553B", R = - "#ED553B"), - aesthetics = "fill" -) +scale_rsi_colours(..., aesthetics = "fill") theme_rsi() @@ -100,7 +96,7 @@ labels_rsi_count( \item{nrow}{(when using \code{facet}) number of rows} -\item{colours}{a named vector with colours for the bars. The names must be one or more of: S, SI, I, IR, R or be \code{FALSE} for standard \link[ggplot2:ggplot]{ggplot2} colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red.} +\item{colours}{a named vactor with colour to be used for filling. The default colours are colour-blind friendly.} \item{datalabels}{show datalabels using \code{\link[=labels_rsi_count]{labels_rsi_count()}}} @@ -118,9 +114,9 @@ labels_rsi_count( \item{y.title}{text to show as y axis description} -\item{...}{other arguments passed on to \code{\link[=geom_rsi]{geom_rsi()}}} +\item{...}{other arguments passed on to \code{\link[=geom_rsi]{geom_rsi()}} or, in case of \code{\link[=scale_rsi_colours]{scale_rsi_colours()}}, named values to set colours. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. See \emph{Examples}.} -\item{aesthetics}{aesthetics to apply the colours to, defaults to "fill" but can also be "colour" or "both"} +\item{aesthetics}{aesthetics to apply the colours to, defaults to "fill" but can also be (a combination of) "alpha", "colour", "fill", "linetype", "shape" or "size"} } \description{ Use these functions to create bar plots for AMR data analysis. All functions rely on \link[ggplot2:ggplot]{ggplot2} functions. @@ -135,7 +131,7 @@ At default, the names of antibiotics will be shown on the plots using \code{\lin \code{\link[=scale_y_percent]{scale_y_percent()}} transforms the y axis to a 0 to 100\% range using \code{\link[ggplot2:scale_continuous]{ggplot2::scale_y_continuous()}}. -\code{\link[=scale_rsi_colours]{scale_rsi_colours()}} sets colours to the bars: pastel blue for S, pastel turquoise for I and pastel red for R, using \code{\link[ggplot2:scale_manual]{ggplot2::scale_fill_manual()}}. +\code{\link[=scale_rsi_colours]{scale_rsi_colours()}} sets colours to the bars (green for S, yellow for I, and red for R). with multilingual support. The default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red. \code{\link[=theme_rsi]{theme_rsi()}} is a [ggplot2 theme][\code{\link[ggplot2:theme]{ggplot2::theme()}} with minimal distraction. diff --git a/man/plot.Rd b/man/plot.Rd index d8b95d10..9d6b010c 100644 --- a/man/plot.Rd +++ b/man/plot.Rd @@ -7,6 +7,7 @@ \alias{plot.disk} \alias{ggplot.disk} \alias{plot.rsi} +\alias{ggplot.rsi} \title{Plotting for Classes \code{rsi}, \code{mic} and \code{disk}} \usage{ \method{plot}{mic}( @@ -38,7 +39,7 @@ \method{plot}{disk}( x, - main = paste("Disk zones values of", deparse(substitute(x))), + main = paste("Disk zones of", deparse(substitute(x))), ylab = "Frequency", xlab = "Disk diffusion diameter (mm)", mo = NULL, @@ -52,7 +53,7 @@ \method{ggplot}{disk}( data, mapping = NULL, - title = paste("Disk zones values of", deparse(substitute(data))), + title = paste("Disk zones of", deparse(substitute(data))), ylab = "Frequency", xlab = "Disk diffusion diameter (mm)", mo = NULL, @@ -70,6 +71,16 @@ main = paste("Resistance Overview of", deparse(substitute(x))), ... ) + +\method{ggplot}{rsi}( + data, + mapping = NULL, + title = paste("Resistance Overview of", deparse(substitute(data))), + xlab = "Antimicrobial Interpretation", + ylab = "Frequency", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + ... +) } \arguments{ \item{x, data}{MIC values created with \code{\link[=as.mic]{as.mic()}} or disk diffusion values created with \code{\link[=as.disk]{as.disk()}}} @@ -121,9 +132,11 @@ On our website \url{https://msberends.github.io/AMR/} you can find \href{https:/ \examples{ some_mic_values <- random_mic(size = 100) some_disk_values <- random_disk(size = 100, mo = "Escherichia coli", ab = "cipro") +some_rsi_values <- random_rsi(50, prob_RSI = c(0.30, 0.55, 0.05)) plot(some_mic_values) plot(some_disk_values) +plot(some_rsi_values) # when providing the microorganism and antibiotic, colours will show interpretations: plot(some_mic_values, mo = "S. aureus", ab = "ampicillin") @@ -132,5 +145,6 @@ plot(some_disk_values, mo = "Escherichia coli", ab = "cipro") if (require("ggplot2")) { ggplot(some_mic_values) ggplot(some_disk_values, mo = "Escherichia coli", ab = "cipro") + ggplot(some_rsi_values) } } diff --git a/pkgdown/extra.css b/pkgdown/extra.css index a0e2a435..093e035c 100644 --- a/pkgdown/extra.css +++ b/pkgdown/extra.css @@ -207,10 +207,11 @@ div[id^=last-updated] h2 { .table thead th { text-align: inherit; } -.table a:not(.btn) { +/* all tables, including argument lists */ +table a:not(.btn) { text-decoration: inherit; } -.table a:not(.btn):hover { +table a:not(.btn):hover { text-decoration: underline; } diff --git a/tests/testthat/test-rsi.R b/tests/testthat/test-rsi.R index 7cc41bc9..2de92259 100644 --- a/tests/testthat/test-rsi.R +++ b/tests/testthat/test-rsi.R @@ -42,6 +42,7 @@ test_that("rsi works", { pdf(NULL) # prevent Rplots.pdf being created expect_silent(barplot(as.rsi(c("S", "I", "R")))) expect_silent(plot(as.rsi(c("S", "I", "R")))) + if (require("ggplot2")) expect_s3_class(ggplot(as.rsi(c("S", "I", "R"))), "gg") expect_output(print(as.rsi(c("S", "I", "R")))) expect_equal(as.character(as.rsi(c(1:3))), c("S", "I", "R")) diff --git a/vignettes/AMR.Rmd b/vignettes/AMR.Rmd index a9b03f2c..d8469160 100755 --- a/vignettes/AMR.Rmd +++ b/vignettes/AMR.Rmd @@ -510,7 +510,7 @@ mic_values <- random_mic(size = 100) mic_values ``` -```{r} +```{r mic_plots} # base R: plot(mic_values) # ggplot2: @@ -520,39 +520,36 @@ ggplot(mic_values) But we could also be more specific, by generating MICs that are likely to be found in *E. coli* for ciprofloxacin: ```{r, results = 'markup', message = FALSE, warning = FALSE} -# this will generate MICs that are likely to be found in E. coli for ciprofloxacin: -mic_values_specific <- random_mic(size = 100, mo = "E. coli", ab = "cipro") +mic_values <- random_mic(size = 100, mo = "E. coli", ab = "cipro") ``` For the `plot()` and `ggplot()` function, we can define the microorganism and an antimicrobial agent the same way. This will add the interpretation of those values according to a chosen guidelines (defaults to the latest EUCAST guideline). Default colours are colour-blind friendly, while maintaining the convention that e.g. 'susceptible' should be green and 'resistant' should be red: -```{r, message = FALSE, warning = FALSE} +```{r mic_plots_mo_ab, message = FALSE, warning = FALSE} # base R: -plot(mic_values_specific, mo = "E. coli", ab = "cipro") +plot(mic_values, mo = "E. coli", ab = "cipro") # ggplot2: -ggplot(mic_values_specific, mo = "E. coli", ab = "cipro") +ggplot(mic_values, mo = "E. coli", ab = "cipro") ``` For disk diffusion values, there is not much of a difference in plotting: ```{r, results = 'markup'} -# this will generate disks that are likely to be found in E. coli for ciprofloxacin: -disk_values_specific <- random_disk(size = 100, mo = "E. coli", ab = "cipro") -disk_values_specific +disk_values <- random_disk(size = 100, mo = "E. coli", ab = "cipro") +disk_values ``` -```{r, message = FALSE, warning = FALSE} +```{r disk_plots, message = FALSE, warning = FALSE} # base R: -plot(disk_values_specific, mo = "E. coli", ab = "cipro") +plot(disk_values, mo = "E. coli", ab = "cipro") ``` And when using the `ggplot2` package, but now choosing the latest implemented CLSI guideline (notice that the EUCAST-specific term "Incr. exposure" has changed to "Intermediate"): -```{r, message = FALSE, warning = FALSE} -# and ggplot2, but now choosing an old CLSI guideline: -ggplot(disk_values_specific, +```{r disk_plots_mo_ab, message = FALSE, warning = FALSE} +ggplot(disk_values, mo = "E. coli", ab = "cipro", guideline = "CLSI")