some_mic_values <- random_mic(size = 100)
-some_disk_values <- random_disk(size = 100, mo = "Escherichia coli", ab = "cipro")
-some_sir_values <- random_sir(50, prob_SIR = c(0.55, 0.05, 0.30))
-
-
-# Plotting using base R's plot() ---------------------------------------
-
-plot(some_mic_values)
-
-plot(some_disk_values)
-
-plot(some_sir_values)
-
-
-# when providing the microorganism and antibiotic, colours will show interpretations:
-plot(some_mic_values, mo = "S. aureus", ab = "ampicillin")
-
-plot(some_disk_values, mo = "Escherichia coli", ab = "cipro")
-
-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.25, "<=4", 4, 8, 32, ">=32")),
- counts = c(1, 1, 2, 2, 3, 3)),
- aes(mics, counts)) +
- geom_col()
- mic_plot +
- labs(title = "without scale_x_mic()")
-}
-
-if (require("ggplot2")) {
- mic_plot +
- scale_x_mic() +
- labs(title = "with scale_x_mic()")
-}
-
-if (require("ggplot2")) {
- mic_plot +
- scale_x_mic(keep_operators = "all") +
- labs(title = "with scale_x_mic() keeping all operators")
-}
-
-if (require("ggplot2")) {
- mic_plot +
- 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")
-}
-
-
-
-# Plotting using scale_y_mic() -----------------------------------------
-some_groups <- sample(LETTERS[1:5], 20, replace = TRUE)
-
-if (require("ggplot2")) {
- ggplot(data.frame(mic = some_mic_values,
- group = some_groups),
- aes(group, mic)) +
- geom_boxplot() +
- geom_violin(linetype = 2, colour = "grey", fill = NA) +
- scale_y_mic()
-}
-
-if (require("ggplot2")) {
- ggplot(data.frame(mic = some_mic_values,
- group = some_groups),
- aes(group, mic)) +
- geom_boxplot() +
- geom_violin(linetype = 2, colour = "grey", fill = NA) +
- scale_y_mic(mic_range = c(NA, 2))
-}
-
-
-
-# Plotting using scale_fill_mic() -----------------------------------------
-some_counts <- as.integer(runif(20, 5, 50))
-
-if (require("ggplot2")) {
- ggplot(data.frame(mic = some_mic_values,
- group = some_groups,
- counts = some_counts),
- aes(group, counts, fill = mic)) +
- geom_col() +
- scale_fill_mic(mic_range = c(0.5, 16))
-}
-
-
-# Plotting using scale_x_sir() -----------------------------------------
-if (require("ggplot2")) {
- ggplot(data.frame(x = c("I", "R", "S"),
- y = c(45,323, 573)),
- aes(x, y)) +
- geom_col() +
- scale_x_sir()
-}
-
-
-
-# Plotting using scale_y_mic() and scale_colour_sir() ------------------
-if (require("ggplot2")) {
- plain <- ggplot(data.frame(mic = some_mic_values,
- group = some_groups,
- sir = as.sir(some_mic_values,
- mo = "E. coli",
- ab = "cipro")),
- aes(x = group, y = mic, colour = sir)) +
- theme_minimal() +
- geom_boxplot(fill = NA, colour = "grey") +
- geom_jitter(width = 0.25)
-
- plain
-}
-#>
-#> ℹ Run sir_interpretation_history() afterwards to retrieve a logbook with
-#> all the details of the breakpoint interpretations.
-#>
-#> Interpreting MIC values: 'cipro' (CIP, ciprofloxacin), EUCAST 2024...
-#> NOTE
-#> • Multiple breakpoints available for ciprofloxacin (CIP) in Escherichia coli - assuming body site 'Non-meningitis'.
-
-if (require("ggplot2")) {
- # and now with our MIC and SIR scale functions:
- plain +
- scale_y_mic() +
- scale_colour_sir()
-}
-
-if (require("ggplot2")) {
- plain +
- scale_y_mic(mic_range = c(0.005, 32), name = "Our MICs!") +
- scale_colour_sir(language = "nl", eucast_I = FALSE,
- name = "In Dutch!")
-}
-
-
-
-# Plotting using ggplot2's autoplot() ----------------------------------
-if (require("ggplot2")) {
- autoplot(some_mic_values)
-}
-
-if (require("ggplot2")) {
- autoplot(some_disk_values, mo = "Escherichia coli", ab = "cipro")
-}
-
-if (require("ggplot2")) {
- autoplot(some_sir_values)
-}
-
-
-
-# Plotting using scale_y_percent() -------------------------------------
-if (require("ggplot2")) {
- p <- 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 / sum(counts))) +
- geom_col()
- print(p)
-
- p2 <- p +
- scale_y_percent() +
- theme_sir()
- print(p2)
-
- p +
- scale_y_percent(breaks = seq(from = 0, to = 1, by = 0.1),
- limits = c(0, 1)) +
- theme_sir()
-}
-
-
-
-# }
-