mirror of
https://github.com/msberends/AMR.git
synced 2024-12-26 09:26:13 +01:00
(v0.6.1.9046) ggplot fix
This commit is contained in:
parent
f03f71eced
commit
4ed27c7e7a
@ -1,5 +1,5 @@
|
|||||||
Package: AMR
|
Package: AMR
|
||||||
Version: 0.6.1.9045
|
Version: 0.6.1.9046
|
||||||
Date: 2019-05-31
|
Date: 2019-05-31
|
||||||
Title: Antimicrobial Resistance Analysis
|
Title: Antimicrobial Resistance Analysis
|
||||||
Authors@R: c(
|
Authors@R: c(
|
||||||
|
4
NEWS.md
4
NEWS.md
@ -22,6 +22,9 @@
|
|||||||
system.file("translations.tsv", package = "AMR")
|
system.file("translations.tsv", package = "AMR")
|
||||||
```
|
```
|
||||||
Please create an issue in one of our repositories if you want additions in this file.
|
Please create an issue in one of our repositories if you want additions in this file.
|
||||||
|
* Improvements to plotting AMR results with `ggplot_rsi()`:
|
||||||
|
* New parameter `colours` to set the bar colours
|
||||||
|
* New parameters `title`, `subtitle`, `caption`, `x.title` and `y.title` to set titles and axis descriptions
|
||||||
* Improved intelligence of looking up antibiotic tables in data set using `guess_ab_col()`
|
* Improved intelligence of looking up antibiotic tables in data set using `guess_ab_col()`
|
||||||
* Added ~5,000 more old taxonomic names to the `microorganisms.old` data set, which leads to better results finding when using the `as.mo()` function
|
* Added ~5,000 more old taxonomic names to the `microorganisms.old` data set, which leads to better results finding when using the `as.mo()` function
|
||||||
* This package now honours the new EUCAST insight (2019) that S and I are but classified as susceptible, where I is defined as 'increased exposure' and not 'intermediate' anymore. For functions like `portion_df()` and `count_df()` this means that their new parameter `combine_SI` is TRUE at default.
|
* This package now honours the new EUCAST insight (2019) that S and I are but classified as susceptible, where I is defined as 'increased exposure' and not 'intermediate' anymore. For functions like `portion_df()` and `count_df()` this means that their new parameter `combine_SI` is TRUE at default.
|
||||||
@ -50,6 +53,7 @@
|
|||||||
* Function `as.mo()` now gently interprets any number of whitespace characters (like tabs) as one space
|
* Function `as.mo()` now gently interprets any number of whitespace characters (like tabs) as one space
|
||||||
* Small algorithm fix for `as.mo()`
|
* Small algorithm fix for `as.mo()`
|
||||||
* Removed viruses from data set `microorganisms.codes` and cleaned it up
|
* Removed viruses from data set `microorganisms.codes` and cleaned it up
|
||||||
|
* Fix for `mo_shortname()` where species would not be determined correctly
|
||||||
|
|
||||||
#### Other
|
#### Other
|
||||||
* Support for R 3.6.0
|
* Support for R 3.6.0
|
||||||
|
20
R/age.R
20
R/age.R
@ -47,8 +47,8 @@ age <- function(x, reference = Sys.Date(), exact = FALSE) {
|
|||||||
stop("`x` and `reference` must be of same length, or `reference` must be of length 1.")
|
stop("`x` and `reference` must be of same length, or `reference` must be of length 1.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x <- base::as.POSIXlt(x)
|
x <- as.POSIXlt(x)
|
||||||
reference <- base::as.POSIXlt(reference)
|
reference <- as.POSIXlt(reference)
|
||||||
|
|
||||||
# from https://stackoverflow.com/a/25450756/4575331
|
# from https://stackoverflow.com/a/25450756/4575331
|
||||||
years_gap <- reference$year - x$year
|
years_gap <- reference$year - x$year
|
||||||
@ -59,13 +59,17 @@ age <- function(x, reference = Sys.Date(), exact = FALSE) {
|
|||||||
# add decimals
|
# add decimals
|
||||||
if (exact == TRUE) {
|
if (exact == TRUE) {
|
||||||
# get dates of `x` when `x` would have the year of `reference`
|
# get dates of `x` when `x` would have the year of `reference`
|
||||||
x_in_reference_year <- base::as.POSIXlt(paste0(format(reference, "%Y"), format(x, "-%m-%d")))
|
x_in_reference_year <- as.POSIXlt(paste0(format(reference, "%Y"), format(x, "-%m-%d")))
|
||||||
# get differences in days
|
# get differences in days
|
||||||
n_days_x_rest <- base::as.double(base::difftime(reference, x_in_reference_year, units = "days"))
|
n_days_x_rest <- as.double(difftime(reference, x_in_reference_year, units = "days"))
|
||||||
# get numbers of days the years of `reference` has for a reliable denominator
|
# get numbers of days the years of `reference` has for a reliable denominator
|
||||||
n_days_reference_year <- base::as.POSIXlt(paste0(format(reference, "%Y"), "-12-31"))$yday + 1
|
n_days_reference_year <- as.POSIXlt(paste0(format(reference, "%Y"), "-12-31"))$yday + 1
|
||||||
# add decimal parts of year
|
# add decimal parts of year
|
||||||
ages <- ages + (n_days_x_rest / n_days_reference_year)
|
mod <- n_days_x_rest / n_days_reference_year
|
||||||
|
# negative mods are cases where `x_in_reference_year` > `reference` - so 'add' a year
|
||||||
|
mod[mod < 0] <- 1 + mod[mod < 0]
|
||||||
|
# and finally add to ages
|
||||||
|
ages <- ages + mod
|
||||||
}
|
}
|
||||||
|
|
||||||
if (any(ages < 0, na.rm = TRUE)) {
|
if (any(ages < 0, na.rm = TRUE)) {
|
||||||
@ -79,10 +83,6 @@ age <- function(x, reference = Sys.Date(), exact = FALSE) {
|
|||||||
ages
|
ages
|
||||||
}
|
}
|
||||||
|
|
||||||
age_to_toDate <- function(age) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#' Split ages into age groups
|
#' Split ages into age groups
|
||||||
#'
|
#'
|
||||||
#' Split ages into age groups defined by the \code{split} parameter. This allows for easier demographic (antimicrobial resistance) analysis.
|
#' Split ages into age groups defined by the \code{split} parameter. This allows for easier demographic (antimicrobial resistance) analysis.
|
||||||
|
170
R/ggplot_rsi.R
170
R/ggplot_rsi.R
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#' AMR plots with \code{ggplot2}
|
#' AMR plots with \code{ggplot2}
|
||||||
#'
|
#'
|
||||||
#' Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal \code{\link[ggplot2]{ggplot}} functions.
|
#' Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal \code{\link[ggplot2]{ggplot}2} functions.
|
||||||
#' @param data a \code{data.frame} with column(s) of class \code{"rsi"} (see \code{\link{as.rsi}})
|
#' @param data a \code{data.frame} with column(s) of class \code{"rsi"} (see \code{\link{as.rsi}})
|
||||||
#' @param position position adjustment of bars, either \code{"fill"} (default when \code{fun} is \code{\link{count_df}}), \code{"stack"} (default when \code{fun} is \code{\link{portion_df}}) or \code{"dodge"}
|
#' @param position position adjustment of bars, either \code{"fill"} (default when \code{fun} is \code{\link{count_df}}), \code{"stack"} (default when \code{fun} is \code{\link{portion_df}}) or \code{"dodge"}
|
||||||
#' @param x variable to show on x axis, either \code{"Antibiotic"} (default) or \code{"Interpretation"} or a grouping variable
|
#' @param x variable to show on x axis, either \code{"Antibiotic"} (default) or \code{"Interpretation"} or a grouping variable
|
||||||
@ -32,11 +32,17 @@
|
|||||||
#' @param fun function to transform \code{data}, either \code{\link{count_df}} (default) or \code{\link{portion_df}}
|
#' @param fun function to transform \code{data}, either \code{\link{count_df}} (default) or \code{\link{portion_df}}
|
||||||
#' @inheritParams portion
|
#' @inheritParams portion
|
||||||
#' @param nrow (when using \code{facet}) number of rows
|
#' @param nrow (when using \code{facet}) number of rows
|
||||||
#' @param datalabels show datalabels using \code{labels_rsi_count}, will at default only be shown when \code{fun = count_df}
|
#' @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 \code{FALSE} to use default \code{ggplot2} colours.
|
||||||
|
#' @param datalabels show datalabels using \code{labels_rsi_count}, will only be shown when \code{fun = count_df}
|
||||||
#' @param datalabels.size size of the datalabels
|
#' @param datalabels.size size of the datalabels
|
||||||
#' @param datalabels.colour colour of the datalabels
|
#' @param datalabels.colour colour of the datalabels
|
||||||
|
#' @param title text to show as title of the plot
|
||||||
|
#' @param subtitle text to show as subtitle of the plot
|
||||||
|
#' @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 parameters passed on to \code{geom_rsi}
|
#' @param ... other parameters passed on to \code{geom_rsi}
|
||||||
#' @details At default, the names of antibiotics will be shown on the plots using \code{\link{ab_name}}. This can be set with the option \code{get_antibiotic_names} (a logical value), so change it e.g. to \code{FALSE} with \code{options(get_antibiotic_names = FALSE)}.
|
#' @details At default, the names of antibiotics will be shown on the plots using \code{\link{ab_name}}. This can be set with the \code{translate_ab} parameter. See \code{\link{count_df}}.
|
||||||
#'
|
#'
|
||||||
#' \strong{The functions}\cr
|
#' \strong{The functions}\cr
|
||||||
#' \code{geom_rsi} will take any variable from the data that has an \code{rsi} class (created with \code{\link{as.rsi}}) using \code{fun} (\code{\link{count_df}} at default, can also be \code{\link{portion_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.
|
#' \code{geom_rsi} will take any variable from the data that has an \code{rsi} class (created with \code{\link{as.rsi}}) using \code{fun} (\code{\link{count_df}} at default, can also be \code{\link{portion_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.
|
||||||
@ -45,7 +51,7 @@
|
|||||||
#'
|
#'
|
||||||
#' \code{scale_y_percent} transforms the y axis to a 0 to 100\% range using \code{\link[ggplot2]{scale_continuous}}.
|
#' \code{scale_y_percent} transforms the y axis to a 0 to 100\% range using \code{\link[ggplot2]{scale_continuous}}.
|
||||||
#'
|
#'
|
||||||
#' \code{scale_rsi_colours} sets colours to the bars: green for S, yellow for I and red for R, using \code{\link[ggplot2]{scale_brewer}}.
|
#' \code{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_brewer}}.
|
||||||
#'
|
#'
|
||||||
#' \code{theme_rsi} is a \code{ggplot \link[ggplot2]{theme}} with minimal distraction.
|
#' \code{theme_rsi} is a \code{ggplot \link[ggplot2]{theme}} with minimal distraction.
|
||||||
#'
|
#'
|
||||||
@ -65,7 +71,7 @@
|
|||||||
#' geom_rsi()
|
#' geom_rsi()
|
||||||
#'
|
#'
|
||||||
#' # prettify the plot using some additional functions:
|
#' # prettify the plot using some additional functions:
|
||||||
#' df <- septic_patients[, c("AMX", "NIT", "FOS", "TMP", "CIP")]
|
#' df <- septic_patients %>% select(AMX, NIT, FOS, TMP, CIP)
|
||||||
#' ggplot(df) +
|
#' ggplot(df) +
|
||||||
#' geom_rsi() +
|
#' geom_rsi() +
|
||||||
#' scale_y_percent() +
|
#' scale_y_percent() +
|
||||||
@ -92,6 +98,10 @@
|
|||||||
#' linetype = 2,
|
#' linetype = 2,
|
||||||
#' alpha = 0.25)
|
#' alpha = 0.25)
|
||||||
#'
|
#'
|
||||||
|
#' septic_patients %>%
|
||||||
|
#' select(AMX) %>%
|
||||||
|
#' ggplot_rsi(colours = c(SI = "yellow"))
|
||||||
|
#'
|
||||||
#' # resistance of ciprofloxacine per age group
|
#' # resistance of ciprofloxacine per age group
|
||||||
#' septic_patients %>%
|
#' septic_patients %>%
|
||||||
#' mutate(first_isolate = first_isolate(.)) %>%
|
#' mutate(first_isolate = first_isolate(.)) %>%
|
||||||
@ -108,45 +118,45 @@
|
|||||||
#' septic_patients %>%
|
#' septic_patients %>%
|
||||||
#' select(AMX, NIT, FOS, TMP, CIP) %>%
|
#' select(AMX, NIT, FOS, TMP, CIP) %>%
|
||||||
#' ggplot_rsi() + scale_fill_viridis_d()
|
#' ggplot_rsi() + scale_fill_viridis_d()
|
||||||
|
#' # a shorter version which also adjusts data label colours:
|
||||||
|
#' septic_patients %>%
|
||||||
|
#' select(AMX, NIT, FOS, TMP, CIP) %>%
|
||||||
|
#' ggplot_rsi(colours = FALSE)
|
||||||
#'
|
#'
|
||||||
#'
|
#'
|
||||||
#' # it also supports groups (don't forget to use the group var on `x` or `facet`):
|
#' # it also supports groups (don't forget to use the group var on `x` or `facet`):
|
||||||
#' septic_patients %>%
|
#' septic_patients %>%
|
||||||
#' select(hospital_id, AMX, NIT, FOS, TMP, CIP) %>%
|
#' select(hospital_id, AMX, NIT, FOS, TMP, CIP) %>%
|
||||||
#' group_by(hospital_id) %>%
|
#' group_by(hospital_id) %>%
|
||||||
#' ggplot_rsi(x = hospital_id,
|
#' ggplot_rsi(x = "hospital_id",
|
||||||
#' facet = Antibiotic,
|
#' facet = "Antibiotic",
|
||||||
#' nrow = 1) +
|
#' nrow = 1,
|
||||||
#' labs(title = "AMR of Anti-UTI Drugs Per Hospital",
|
#' title = "AMR of Anti-UTI Drugs Per Hospital",
|
||||||
#' x = "Hospital")
|
#' x.title = "Hospital",
|
||||||
|
#' datalabels = FALSE)
|
||||||
#'
|
#'
|
||||||
#' # genuine analysis: check 2 most prevalent microorganisms
|
#' # genuine analysis: check 3 most prevalent microorganisms
|
||||||
#' septic_patients %>%
|
#' septic_patients %>%
|
||||||
#' # create new bacterial ID's, with all CoNS under the same group (Becker et al.)
|
#' # create new bacterial ID's, with all CoNS under the same group (Becker et al.)
|
||||||
#' mutate(mo = as.mo(mo, Becker = TRUE)) %>%
|
#' mutate(mo = as.mo(mo, Becker = TRUE)) %>%
|
||||||
#' # filter on top three bacterial ID's
|
#' # filter on top three bacterial ID's
|
||||||
#' filter(mo %in% top_freq(freq(.$mo), 3)) %>%
|
#' filter(mo %in% top_freq(freq(.$mo), 3)) %>%
|
||||||
#' # determine first isolates
|
|
||||||
#' mutate(first_isolate = first_isolate(.,
|
|
||||||
#' col_date = "date",
|
|
||||||
#' col_patient_id = "patient_id",
|
|
||||||
#' col_mo = "mo")) %>%
|
|
||||||
#' # filter on first isolates
|
#' # filter on first isolates
|
||||||
#' filter(first_isolate == TRUE) %>%
|
#' filter_first_isolate() %>%
|
||||||
#' # get short MO names (like "E. coli")
|
#' # get short MO names (like "E. coli")
|
||||||
#' mutate(mo = mo_shortname(mo, Becker = TRUE)) %>%
|
#' mutate(bug = mo_shortname(mo, Becker = TRUE)) %>%
|
||||||
#' # select this short name and some antiseptic drugs
|
#' # select this short name and some antiseptic drugs
|
||||||
#' select(mo, CXM, GEN, CIP) %>%
|
#' select(bug, CXM, GEN, CIP) %>%
|
||||||
#' # group by MO
|
#' # group by MO
|
||||||
#' group_by(mo) %>%
|
#' group_by(bug) %>%
|
||||||
#' # plot the thing, putting MOs on the facet
|
#' # plot the thing, putting MOs on the facet
|
||||||
#' ggplot_rsi(x = Antibiotic,
|
#' ggplot_rsi(x = "Antibiotic",
|
||||||
#' facet = mo,
|
#' facet = "bug",
|
||||||
#' translate_ab = FALSE,
|
#' translate_ab = FALSE,
|
||||||
#' nrow = 1) +
|
#' nrow = 1,
|
||||||
#' labs(title = "AMR of Top Three Microorganisms In Blood Culture Isolates",
|
#' title = "AMR of Top Three Microorganisms In Blood Culture Isolates",
|
||||||
#' subtitle = "Only First Isolates, CoNS grouped according to Becker et al. (2014)",
|
#' subtitle = expression(paste("Only First Isolates, CoNS grouped according to Becker ", italic("et al."), " (2014)")),
|
||||||
#' x = "Microorganisms")
|
#' x.title = "Antibiotic (EARS-Net code)")
|
||||||
#' }
|
#' }
|
||||||
ggplot_rsi <- function(data,
|
ggplot_rsi <- function(data,
|
||||||
position = NULL,
|
position = NULL,
|
||||||
@ -162,9 +172,19 @@ ggplot_rsi <- function(data,
|
|||||||
language = get_locale(),
|
language = get_locale(),
|
||||||
fun = count_df,
|
fun = count_df,
|
||||||
nrow = NULL,
|
nrow = NULL,
|
||||||
datalabels = FALSE,
|
colours = c(S = "#61a8ff",
|
||||||
datalabels.size = 3,
|
SI = "#61a8ff",
|
||||||
datalabels.colour = "white",
|
I = "#61f7ff",
|
||||||
|
IR = "#ff6961",
|
||||||
|
R = "#ff6961"),
|
||||||
|
datalabels = TRUE,
|
||||||
|
datalabels.size = 2.5,
|
||||||
|
datalabels.colour = "gray15",
|
||||||
|
title = NULL,
|
||||||
|
subtitle = NULL,
|
||||||
|
caption = NULL,
|
||||||
|
x.title = NULL,
|
||||||
|
y.title = NULL,
|
||||||
...) {
|
...) {
|
||||||
|
|
||||||
stopifnot_installed_package("ggplot2")
|
stopifnot_installed_package("ggplot2")
|
||||||
@ -196,6 +216,10 @@ ggplot_rsi <- function(data,
|
|||||||
facet <- NULL
|
facet <- NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is.null(position)) {
|
||||||
|
position <- "fill"
|
||||||
|
}
|
||||||
|
|
||||||
p <- ggplot2::ggplot(data = data) +
|
p <- ggplot2::ggplot(data = data) +
|
||||||
geom_rsi(position = position, x = x, fill = fill, translate_ab = translate_ab,
|
geom_rsi(position = position, x = x, fill = fill, translate_ab = translate_ab,
|
||||||
fun = fun, combine_SI = combine_SI, combine_IR = combine_IR, ...) +
|
fun = fun, combine_SI = combine_SI, combine_IR = combine_IR, ...) +
|
||||||
@ -203,11 +227,13 @@ ggplot_rsi <- function(data,
|
|||||||
|
|
||||||
if (fill == "Interpretation") {
|
if (fill == "Interpretation") {
|
||||||
# set RSI colours
|
# set RSI colours
|
||||||
p <- p + scale_rsi_colours()
|
if (isFALSE(colours) & missing(datalabels.colour)) {
|
||||||
}
|
# set datalabel colour to middle gray
|
||||||
if (is.null(position)) {
|
datalabels.colour <- "gray50"
|
||||||
position <- "fill"
|
}
|
||||||
|
p <- p + scale_rsi_colours(colours = colours)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fun_name == "portion_df"
|
if (fun_name == "portion_df"
|
||||||
| (fun_name == "count_df" & identical(position, "fill"))) {
|
| (fun_name == "count_df" & identical(position, "fill"))) {
|
||||||
# portions, so use y scale with percentage
|
# portions, so use y scale with percentage
|
||||||
@ -217,6 +243,9 @@ ggplot_rsi <- function(data,
|
|||||||
if (fun_name == "count_df" & datalabels == TRUE) {
|
if (fun_name == "count_df" & datalabels == TRUE) {
|
||||||
p <- p + labels_rsi_count(position = position,
|
p <- p + labels_rsi_count(position = position,
|
||||||
x = x,
|
x = x,
|
||||||
|
translate_ab = translate_ab,
|
||||||
|
combine_SI = combine_SI,
|
||||||
|
combine_IR = combine_IR,
|
||||||
datalabels.size = datalabels.size,
|
datalabels.size = datalabels.size,
|
||||||
datalabels.colour = datalabels.colour)
|
datalabels.colour = datalabels.colour)
|
||||||
}
|
}
|
||||||
@ -225,6 +254,12 @@ ggplot_rsi <- function(data,
|
|||||||
p <- p + facet_rsi(facet = facet, nrow = nrow)
|
p <- p + facet_rsi(facet = facet, nrow = nrow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p <- p + ggplot2::labs(title = title,
|
||||||
|
subtitle = subtitle,
|
||||||
|
caption = caption,
|
||||||
|
x = x.title,
|
||||||
|
y = y.title)
|
||||||
|
|
||||||
p
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,6 +296,10 @@ geom_rsi <- function(position = NULL,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (identical(position, "fill")) {
|
||||||
|
position <- ggplot2::position_fill(vjust = 0.5, reverse = TRUE)
|
||||||
|
}
|
||||||
|
|
||||||
x <- x[1]
|
x <- x[1]
|
||||||
|
|
||||||
# we work with aes_string later on
|
# we work with aes_string later on
|
||||||
@ -296,7 +335,7 @@ facet_rsi <- function(facet = c("Interpretation", "Antibiotic"), nrow = NULL) {
|
|||||||
|
|
||||||
stopifnot_installed_package("ggplot2")
|
stopifnot_installed_package("ggplot2")
|
||||||
|
|
||||||
facet <- facet[1]
|
facet <- facet[1]
|
||||||
|
|
||||||
# we work with aes_string later on
|
# we work with aes_string later on
|
||||||
facet_deparse <- deparse(substitute(facet))
|
facet_deparse <- deparse(substitute(facet))
|
||||||
@ -331,37 +370,49 @@ scale_y_percent <- function(breaks = seq(0, 1, 0.1), limits = NULL) {
|
|||||||
|
|
||||||
#' @rdname ggplot_rsi
|
#' @rdname ggplot_rsi
|
||||||
#' @export
|
#' @export
|
||||||
scale_rsi_colours <- function() {
|
scale_rsi_colours <- function(colours = c(S = "#61a8ff",
|
||||||
|
SI = "#61a8ff",
|
||||||
|
I = "#61f7ff",
|
||||||
|
IR = "#ff6961",
|
||||||
|
R = "#ff6961")) {
|
||||||
stopifnot_installed_package("ggplot2")
|
stopifnot_installed_package("ggplot2")
|
||||||
#ggplot2::scale_fill_brewer(palette = "RdYlGn")
|
#ggplot2::scale_fill_brewer(palette = "RdYlGn")
|
||||||
#ggplot2::scale_fill_manual(values = c("#b22222", "#ae9c20", "#7cfc00"))
|
#ggplot2::scale_fill_manual(values = c("#b22222", "#ae9c20", "#7cfc00"))
|
||||||
|
|
||||||
# mixed using https://www.colorhexa.com/b22222
|
if (!identical(colours, FALSE)) {
|
||||||
# and https://www.w3schools.com/colors/colors_mixer.asp
|
original_cols <- c(S = "#61a8ff",
|
||||||
ggplot2::scale_fill_manual(values = c(S = "#22b222",
|
SI = "#61a8ff",
|
||||||
SI = "#22b222",
|
I = "#61f7ff",
|
||||||
I = "#548022",
|
IR = "#ff6961",
|
||||||
IR = "#b22222",
|
R = "#ff6961")
|
||||||
R = "#b22222"))
|
colours <- replace(original_cols, names(colours), colours)
|
||||||
|
ggplot2::scale_fill_manual(values = colours)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#' @rdname ggplot_rsi
|
#' @rdname ggplot_rsi
|
||||||
#' @export
|
#' @export
|
||||||
theme_rsi <- function() {
|
theme_rsi <- function() {
|
||||||
stopifnot_installed_package("ggplot2")
|
stopifnot_installed_package("ggplot2")
|
||||||
ggplot2::theme_minimal() +
|
ggplot2::theme_minimal(base_size = 10) +
|
||||||
ggplot2::theme(panel.grid.major.x = ggplot2::element_blank(),
|
ggplot2::theme(panel.grid.major.x = ggplot2::element_blank(),
|
||||||
panel.grid.minor = ggplot2::element_blank(),
|
panel.grid.minor = ggplot2::element_blank(),
|
||||||
panel.grid.major.y = ggplot2::element_line(colour = "grey75"))
|
panel.grid.major.y = ggplot2::element_line(colour = "grey75"),
|
||||||
|
# center title and subtitle
|
||||||
|
plot.title = ggplot2::element_text(hjust = 0.5),
|
||||||
|
plot.subtitle = ggplot2::element_text(hjust = 0.5))
|
||||||
}
|
}
|
||||||
|
|
||||||
#' @rdname ggplot_rsi
|
#' @rdname ggplot_rsi
|
||||||
|
#' @importFrom dplyr mutate %>% group_by_at
|
||||||
#' @export
|
#' @export
|
||||||
labels_rsi_count <- function(position = NULL,
|
labels_rsi_count <- function(position = NULL,
|
||||||
x = "Antibiotic",
|
x = "Antibiotic",
|
||||||
|
translate_ab = "name",
|
||||||
|
combine_SI = TRUE,
|
||||||
|
combine_IR = FALSE,
|
||||||
datalabels.size = 3,
|
datalabels.size = 3,
|
||||||
datalabels.colour = "white") {
|
datalabels.colour = "gray15") {
|
||||||
stopifnot_installed_package("ggplot2")
|
stopifnot_installed_package("ggplot2")
|
||||||
if (is.null(position)) {
|
if (is.null(position)) {
|
||||||
position <- "fill"
|
position <- "fill"
|
||||||
@ -369,23 +420,24 @@ labels_rsi_count <- function(position = NULL,
|
|||||||
if (identical(position, "fill")) {
|
if (identical(position, "fill")) {
|
||||||
position <- ggplot2::position_fill(vjust = 0.5, reverse = TRUE)
|
position <- ggplot2::position_fill(vjust = 0.5, reverse = TRUE)
|
||||||
}
|
}
|
||||||
|
x_name <- x
|
||||||
ggplot2::geom_text(mapping = ggplot2::aes_string(label = "lbl",
|
ggplot2::geom_text(mapping = ggplot2::aes_string(label = "lbl",
|
||||||
x = x,
|
x = x,
|
||||||
y = "Value"),
|
y = "Value"),
|
||||||
position = position,
|
position = position,
|
||||||
data = getlbls,
|
|
||||||
inherit.aes = FALSE,
|
inherit.aes = FALSE,
|
||||||
size = datalabels.size,
|
size = datalabels.size,
|
||||||
colour = datalabels.colour)
|
colour = datalabels.colour,
|
||||||
|
lineheight = 0.75,
|
||||||
|
data = function(x) {
|
||||||
|
# labels are only shown when function is count_df,
|
||||||
|
# so no need parameterise it here
|
||||||
|
count_df(data = x,
|
||||||
|
translate_ab = translate_ab,
|
||||||
|
combine_SI = combine_SI,
|
||||||
|
combine_IR = combine_IR) %>%
|
||||||
|
group_by_at(x_name) %>%
|
||||||
|
mutate(lbl = paste0(percent(Value / sum(Value, na.rm = TRUE), force_zero = TRUE),
|
||||||
|
"\n(n=", Value, ")"))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#' @importFrom dplyr %>% group_by mutate
|
|
||||||
getlbls <- function(data) {
|
|
||||||
data %>%
|
|
||||||
count_df() %>%
|
|
||||||
group_by(Antibiotic) %>%
|
|
||||||
mutate(lbl = paste0(percent(Value / sum(Value, na.rm = TRUE), force_zero = TRUE),
|
|
||||||
" (n=", Value, ")")) %>%
|
|
||||||
mutate(lbl = ifelse(lbl == "0.0% (n=0)", "", lbl))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -157,55 +157,32 @@ mo_shortname <- function(x, language = get_locale(), ...) {
|
|||||||
Lancefield <- FALSE
|
Lancefield <- FALSE
|
||||||
}
|
}
|
||||||
|
|
||||||
shorten <- function(x) {
|
# get result without transformations
|
||||||
# easiest: no transformations needed
|
res1 <- AMR::as.mo(x, Becker = FALSE, Lancefield = FALSE, reference_df = dots$reference_df)
|
||||||
x <- mo_fullname(x, language = "en")
|
# and result with transformations
|
||||||
# shorten for the ones that have a space: shorten first word and write out second word
|
res2 <- suppressWarnings(AMR::as.mo(res1, ...))
|
||||||
shorten_these <- x %like% " " & !x %like% "Streptococcus group "
|
res2_fullname <- mo_fullname(res2, language = language)
|
||||||
x[shorten_these] <- paste0(substr(x[shorten_these], 1, 1),
|
res2_fullname[res2_fullname %like% " \\(CoNS\\)"] <- "CoNS"
|
||||||
". ",
|
res2_fullname[res2_fullname %like% " \\(CoPS\\)"] <- "CoPS"
|
||||||
x[shorten_these] %>%
|
res2_fullname[res2_fullname %like% " \\(KNS\\)"] <- "KNS"
|
||||||
strsplit(" ", fixed = TRUE) %>%
|
res2_fullname[res2_fullname %like% " \\(KPS\\)"] <- "KPS"
|
||||||
unlist() %>%
|
res2_fullname[res2_fullname %like% " \\(CNS\\)"] <- "CNS"
|
||||||
.[2])
|
res2_fullname[res2_fullname %like% " \\(CPS\\)"] <- "CPS"
|
||||||
x
|
res2_fullname[res2_fullname %like% " \\(SCN\\)"] <- "SCN"
|
||||||
}
|
res2_fullname <- gsub("Streptococcus (group|Gruppe|gruppe|groep|grupo|gruppo|groupe) (.)",
|
||||||
|
"G\\2S",
|
||||||
if (isFALSE(Becker) & isFALSE(Lancefield)) {
|
res2_fullname) # turn "Streptococcus group A" and "Streptococcus grupo A" to "GAS"
|
||||||
result <- shorten(x)
|
res2_fullname_vector <- res2_fullname[res2_fullname == mo_fullname(res1)]
|
||||||
|
res2_fullname[res2_fullname == mo_fullname(res1)] <- paste0(substr(mo_genus(res2_fullname_vector), 1, 1),
|
||||||
} else {
|
". ",
|
||||||
# get result without transformations
|
suppressWarnings(mo_species(res2_fullname_vector)))
|
||||||
res1 <- AMR::as.mo(x, Becker = FALSE, Lancefield = FALSE, reference_df = dots$reference_df)
|
if (sum(res1 == res2, na.rm = TRUE) > 0) {
|
||||||
# and result with transformations
|
res1[res1 == res2] <- paste0(substr(mo_genus(res1[res1 == res2]), 1, 1),
|
||||||
res2 <- suppressWarnings(AMR::as.mo(res1, ...))
|
". ",
|
||||||
if (res1 == res2
|
suppressWarnings(mo_species(res1[res1 == res2])))
|
||||||
& !res1 %like% "^B_STRPT_GR") {
|
|
||||||
result <- shorten(x)
|
|
||||||
} else {
|
|
||||||
res2_fullname <- mo_fullname(res2, language = language)
|
|
||||||
res2_fullname[res2_fullname %like% " \\(CoNS\\)"] <- "CoNS"
|
|
||||||
res2_fullname[res2_fullname %like% " \\(CoPS\\)"] <- "CoPS"
|
|
||||||
res2_fullname[res2_fullname %like% " \\(KNS\\)"] <- "KNS"
|
|
||||||
res2_fullname[res2_fullname %like% " \\(KPS\\)"] <- "KPS"
|
|
||||||
res2_fullname[res2_fullname %like% " \\(CNS\\)"] <- "CNS"
|
|
||||||
res2_fullname[res2_fullname %like% " \\(CPS\\)"] <- "CPS"
|
|
||||||
res2_fullname <- gsub("Streptococcus (group|Gruppe|gruppe|groep|grupo|gruppo|groupe) (.)",
|
|
||||||
"G\\2S",
|
|
||||||
res2_fullname) # turn "Streptococcus group A" and "Streptococcus grupo A" to "GAS"
|
|
||||||
res2_fullname_vector <- res2_fullname[res2_fullname == mo_fullname(res1)]
|
|
||||||
res2_fullname[res2_fullname == mo_fullname(res1)] <- paste0(substr(mo_genus(res2_fullname_vector), 1, 1),
|
|
||||||
". ",
|
|
||||||
suppressWarnings(mo_species(res2_fullname_vector)))
|
|
||||||
if (sum(res1 == res2, na.rm = TRUE) > 0) {
|
|
||||||
res1[res1 == res2] <- paste0(substr(mo_genus(res1[res1 == res2]), 1, 1),
|
|
||||||
". ",
|
|
||||||
suppressWarnings(mo_species(res1[res1 == res2])))
|
|
||||||
}
|
|
||||||
res1[res1 != res2] <- res2_fullname
|
|
||||||
result <- as.character(res1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
res1[res1 != res2] <- res2_fullname
|
||||||
|
result <- as.character(res1)
|
||||||
|
|
||||||
t(result, language = language)
|
t(result, language = language)
|
||||||
}
|
}
|
||||||
|
10
_pkgdown.yml
10
_pkgdown.yml
@ -19,9 +19,12 @@
|
|||||||
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
|
||||||
# ==================================================================== #
|
# ==================================================================== #
|
||||||
|
|
||||||
url: 'https://msberends.gitlab.io/AMR'
|
|
||||||
|
|
||||||
title: 'AMR (for R)'
|
title: 'AMR (for R)'
|
||||||
|
url: 'https://msberends.gitlab.io/AMR'
|
||||||
|
development:
|
||||||
|
mode: release # improves indexing by search engines
|
||||||
|
news:
|
||||||
|
one_page: true
|
||||||
|
|
||||||
navbar:
|
navbar:
|
||||||
title: 'AMR (for R)'
|
title: 'AMR (for R)'
|
||||||
@ -177,9 +180,6 @@ authors:
|
|||||||
Bhanu N. M. Sinha:
|
Bhanu N. M. Sinha:
|
||||||
href: https://www.rug.nl/staff/b.sinha/
|
href: https://www.rug.nl/staff/b.sinha/
|
||||||
|
|
||||||
development:
|
|
||||||
mode: release # improves indexing by search engines
|
|
||||||
|
|
||||||
template:
|
template:
|
||||||
assets: pkgdown/logos # use logos in this folder
|
assets: pkgdown/logos # use logos in this folder
|
||||||
params:
|
params:
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9045</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9046</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9045</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9046</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9045</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9046</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
<a class="navbar-link" href="index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9045</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9046</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9045</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9046</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -278,6 +278,12 @@
|
|||||||
Please create an issue in one of our repositories if you want additions in this file.</li>
|
Please create an issue in one of our repositories if you want additions in this file.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
<li>Improvements to plotting AMR results with <code><a href="../reference/ggplot_rsi.html">ggplot_rsi()</a></code>:
|
||||||
|
<ul>
|
||||||
|
<li>New parameter <code>colours</code> to set the bar colours</li>
|
||||||
|
<li>New parameters <code>title</code>, <code>subtitle</code>, <code>caption</code>, <code>x.title</code> and <code>y.title</code> to set titles and axis descriptions</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
<li>Improved intelligence of looking up antibiotic tables in data set using <code><a href="../reference/guess_ab_col.html">guess_ab_col()</a></code>
|
<li>Improved intelligence of looking up antibiotic tables in data set using <code><a href="../reference/guess_ab_col.html">guess_ab_col()</a></code>
|
||||||
</li>
|
</li>
|
||||||
<li>Added ~5,000 more old taxonomic names to the <code>microorganisms.old</code> data set, which leads to better results finding when using the <code><a href="../reference/as.mo.html">as.mo()</a></code> function</li>
|
<li>Added ~5,000 more old taxonomic names to the <code>microorganisms.old</code> data set, which leads to better results finding when using the <code><a href="../reference/as.mo.html">as.mo()</a></code> function</li>
|
||||||
@ -316,6 +322,7 @@ Please create an issue in one of our repositories if you want additions in this
|
|||||||
<li>Small algorithm fix for <code><a href="../reference/as.mo.html">as.mo()</a></code>
|
<li>Small algorithm fix for <code><a href="../reference/as.mo.html">as.mo()</a></code>
|
||||||
</li>
|
</li>
|
||||||
<li>Removed viruses from data set <code>microorganisms.codes</code> and cleaned it up</li>
|
<li>Removed viruses from data set <code>microorganisms.codes</code> and cleaned it up</li>
|
||||||
|
<li>Fix for <code><a href="../reference/mo_property.html">mo_shortname()</a></code> where species would not be determined correctly</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="other" class="section level4">
|
<div id="other" class="section level4">
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
<script src="../extra.js"></script>
|
<script src="../extra.js"></script>
|
||||||
<meta property="og:title" content="AMR plots with <code>ggplot2</code> — ggplot_rsi" />
|
<meta property="og:title" content="AMR plots with <code>ggplot2</code> — ggplot_rsi" />
|
||||||
|
|
||||||
<meta property="og:description" content="Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal ggplot functions." />
|
<meta property="og:description" content="Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal ggplot2 functions." />
|
||||||
|
|
||||||
<meta property="og:image" content="https://msberends.gitlab.io/AMR/logo.png" />
|
<meta property="og:image" content="https://msberends.gitlab.io/AMR/logo.png" />
|
||||||
<meta name="twitter:card" content="summary" />
|
<meta name="twitter:card" content="summary" />
|
||||||
@ -80,7 +80,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9044</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9046</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -244,7 +244,7 @@
|
|||||||
|
|
||||||
<div class="ref-description">
|
<div class="ref-description">
|
||||||
|
|
||||||
<p>Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal <code><a href='https://www.rdocumentation.org/packages/ggplot2/topics/ggplot'>ggplot</a></code> functions.</p>
|
<p>Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal <code><a href='https://www.rdocumentation.org/packages/ggplot2/topics/ggplot'>ggplot</a>2</code> functions.</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -252,8 +252,11 @@
|
|||||||
<span class='kw'>fill</span> <span class='kw'>=</span> <span class='st'>"Interpretation"</span>, <span class='kw'>facet</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>breaks</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/seq'>seq</a></span>(<span class='fl'>0</span>, <span class='fl'>1</span>, <span class='fl'>0.1</span>),
|
<span class='kw'>fill</span> <span class='kw'>=</span> <span class='st'>"Interpretation"</span>, <span class='kw'>facet</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>breaks</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/seq'>seq</a></span>(<span class='fl'>0</span>, <span class='fl'>1</span>, <span class='fl'>0.1</span>),
|
||||||
<span class='kw'>limits</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>translate_ab</span> <span class='kw'>=</span> <span class='st'>"name"</span>, <span class='kw'>combine_SI</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>,
|
<span class='kw'>limits</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>translate_ab</span> <span class='kw'>=</span> <span class='st'>"name"</span>, <span class='kw'>combine_SI</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>,
|
||||||
<span class='kw'>combine_IR</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>, <span class='kw'>language</span> <span class='kw'>=</span> <span class='fu'><a href='translate.html'>get_locale</a></span>(), <span class='kw'>fun</span> <span class='kw'>=</span> <span class='no'>count_df</span>,
|
<span class='kw'>combine_IR</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>, <span class='kw'>language</span> <span class='kw'>=</span> <span class='fu'><a href='translate.html'>get_locale</a></span>(), <span class='kw'>fun</span> <span class='kw'>=</span> <span class='no'>count_df</span>,
|
||||||
<span class='kw'>nrow</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>datalabels</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>, <span class='kw'>datalabels.size</span> <span class='kw'>=</span> <span class='fl'>3</span>,
|
<span class='kw'>nrow</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>colours</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/c'>c</a></span>(<span class='kw'>S</span> <span class='kw'>=</span> <span class='st'>"#61a8ff"</span>, <span class='kw'>SI</span> <span class='kw'>=</span> <span class='st'>"#61a8ff"</span>, <span class='kw'>I</span> <span class='kw'>=</span>
|
||||||
<span class='kw'>datalabels.colour</span> <span class='kw'>=</span> <span class='st'>"white"</span>, <span class='no'>...</span>)
|
<span class='st'>"#61f7ff"</span>, <span class='kw'>IR</span> <span class='kw'>=</span> <span class='st'>"#ff6961"</span>, <span class='kw'>R</span> <span class='kw'>=</span> <span class='st'>"#ff6961"</span>), <span class='kw'>datalabels</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>,
|
||||||
|
<span class='kw'>datalabels.size</span> <span class='kw'>=</span> <span class='fl'>2.5</span>, <span class='kw'>datalabels.colour</span> <span class='kw'>=</span> <span class='st'>"gray15"</span>, <span class='kw'>title</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
|
||||||
|
<span class='kw'>subtitle</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>caption</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>x.title</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>y.title</span> <span class='kw'>=</span> <span class='kw'>NULL</span>,
|
||||||
|
<span class='no'>...</span>)
|
||||||
|
|
||||||
<span class='fu'>geom_rsi</span>(<span class='kw'>position</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>x</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/c'>c</a></span>(<span class='st'>"Antibiotic"</span>, <span class='st'>"Interpretation"</span>),
|
<span class='fu'>geom_rsi</span>(<span class='kw'>position</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>x</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/c'>c</a></span>(<span class='st'>"Antibiotic"</span>, <span class='st'>"Interpretation"</span>),
|
||||||
<span class='kw'>fill</span> <span class='kw'>=</span> <span class='st'>"Interpretation"</span>, <span class='kw'>translate_ab</span> <span class='kw'>=</span> <span class='st'>"name"</span>,
|
<span class='kw'>fill</span> <span class='kw'>=</span> <span class='st'>"Interpretation"</span>, <span class='kw'>translate_ab</span> <span class='kw'>=</span> <span class='st'>"name"</span>,
|
||||||
@ -264,12 +267,14 @@
|
|||||||
|
|
||||||
<span class='fu'>scale_y_percent</span>(<span class='kw'>breaks</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/seq'>seq</a></span>(<span class='fl'>0</span>, <span class='fl'>1</span>, <span class='fl'>0.1</span>), <span class='kw'>limits</span> <span class='kw'>=</span> <span class='kw'>NULL</span>)
|
<span class='fu'>scale_y_percent</span>(<span class='kw'>breaks</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/seq'>seq</a></span>(<span class='fl'>0</span>, <span class='fl'>1</span>, <span class='fl'>0.1</span>), <span class='kw'>limits</span> <span class='kw'>=</span> <span class='kw'>NULL</span>)
|
||||||
|
|
||||||
<span class='fu'>scale_rsi_colours</span>()
|
<span class='fu'>scale_rsi_colours</span>(<span class='kw'>colours</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/c'>c</a></span>(<span class='kw'>S</span> <span class='kw'>=</span> <span class='st'>"#61a8ff"</span>, <span class='kw'>SI</span> <span class='kw'>=</span> <span class='st'>"#61a8ff"</span>, <span class='kw'>I</span> <span class='kw'>=</span>
|
||||||
|
<span class='st'>"#61f7ff"</span>, <span class='kw'>IR</span> <span class='kw'>=</span> <span class='st'>"#ff6961"</span>, <span class='kw'>R</span> <span class='kw'>=</span> <span class='st'>"#ff6961"</span>))
|
||||||
|
|
||||||
<span class='fu'>theme_rsi</span>()
|
<span class='fu'>theme_rsi</span>()
|
||||||
|
|
||||||
<span class='fu'>labels_rsi_count</span>(<span class='kw'>position</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>x</span> <span class='kw'>=</span> <span class='st'>"Antibiotic"</span>,
|
<span class='fu'>labels_rsi_count</span>(<span class='kw'>position</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>x</span> <span class='kw'>=</span> <span class='st'>"Antibiotic"</span>,
|
||||||
<span class='kw'>datalabels.size</span> <span class='kw'>=</span> <span class='fl'>3</span>, <span class='kw'>datalabels.colour</span> <span class='kw'>=</span> <span class='st'>"white"</span>)</pre>
|
<span class='kw'>translate_ab</span> <span class='kw'>=</span> <span class='st'>"name"</span>, <span class='kw'>combine_SI</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>, <span class='kw'>combine_IR</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
|
||||||
|
<span class='kw'>datalabels.size</span> <span class='kw'>=</span> <span class='fl'>3</span>, <span class='kw'>datalabels.colour</span> <span class='kw'>=</span> <span class='st'>"gray15"</span>)</pre>
|
||||||
|
|
||||||
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
|
<h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
|
||||||
<table class="ref-arguments">
|
<table class="ref-arguments">
|
||||||
@ -326,9 +331,13 @@
|
|||||||
<th>nrow</th>
|
<th>nrow</th>
|
||||||
<td><p>(when using <code>facet</code>) number of rows</p></td>
|
<td><p>(when using <code>facet</code>) number of rows</p></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>colours</th>
|
||||||
|
<td><p>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</code> to use default <code>ggplot2</code> colours.</p></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>datalabels</th>
|
<th>datalabels</th>
|
||||||
<td><p>show datalabels using <code>labels_rsi_count</code>, will at default only be shown when <code>fun = count_df</code></p></td>
|
<td><p>show datalabels using <code>labels_rsi_count</code>, will only be shown when <code>fun = count_df</code></p></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>datalabels.size</th>
|
<th>datalabels.size</th>
|
||||||
@ -338,6 +347,26 @@
|
|||||||
<th>datalabels.colour</th>
|
<th>datalabels.colour</th>
|
||||||
<td><p>colour of the datalabels</p></td>
|
<td><p>colour of the datalabels</p></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>title</th>
|
||||||
|
<td><p>text to show as title of the plot</p></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>subtitle</th>
|
||||||
|
<td><p>text to show as subtitle of the plot</p></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>caption</th>
|
||||||
|
<td><p>text to show as caption of the plot</p></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>x.title</th>
|
||||||
|
<td><p>text to show as x axis description</p></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>y.title</th>
|
||||||
|
<td><p>text to show as y axis description</p></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>...</th>
|
<th>...</th>
|
||||||
<td><p>other parameters passed on to <code>geom_rsi</code></p></td>
|
<td><p>other parameters passed on to <code>geom_rsi</code></p></td>
|
||||||
@ -346,12 +375,12 @@
|
|||||||
|
|
||||||
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
|
<h2 class="hasAnchor" id="details"><a class="anchor" href="#details"></a>Details</h2>
|
||||||
|
|
||||||
<p>At default, the names of antibiotics will be shown on the plots using <code><a href='ab_property.html'>ab_name</a></code>. This can be set with the option <code>get_antibiotic_names</code> (a logical value), so change it e.g. to <code>FALSE</code> with <code><a href='https://www.rdocumentation.org/packages/base/topics/options'>options(get_antibiotic_names = FALSE)</a></code>.</p>
|
<p>At default, the names of antibiotics will be shown on the plots using <code><a href='ab_property.html'>ab_name</a></code>. This can be set with the <code>translate_ab</code> parameter. See <code><a href='count.html'>count_df</a></code>.</p>
|
||||||
<p><strong>The functions</strong><br />
|
<p><strong>The functions</strong><br />
|
||||||
<code>geom_rsi</code> will take any variable from the data that has an <code>rsi</code> class (created with <code><a href='as.rsi.html'>as.rsi</a></code>) using <code>fun</code> (<code><a href='count.html'>count_df</a></code> at default, can also be <code><a href='portion.html'>portion_df</a></code>) 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.</p>
|
<code>geom_rsi</code> will take any variable from the data that has an <code>rsi</code> class (created with <code><a href='as.rsi.html'>as.rsi</a></code>) using <code>fun</code> (<code><a href='count.html'>count_df</a></code> at default, can also be <code><a href='portion.html'>portion_df</a></code>) 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.</p>
|
||||||
<p><code>facet_rsi</code> creates 2d plots (at default based on S/I/R) using <code><a href='https://www.rdocumentation.org/packages/ggplot2/topics/facet_wrap'>facet_wrap</a></code>.</p>
|
<p><code>facet_rsi</code> creates 2d plots (at default based on S/I/R) using <code><a href='https://www.rdocumentation.org/packages/ggplot2/topics/facet_wrap'>facet_wrap</a></code>.</p>
|
||||||
<p><code>scale_y_percent</code> transforms the y axis to a 0 to 100% range using <code>scale_continuous</code>.</p>
|
<p><code>scale_y_percent</code> transforms the y axis to a 0 to 100% range using <code>scale_continuous</code>.</p>
|
||||||
<p><code>scale_rsi_colours</code> sets colours to the bars: green for S, yellow for I and red for R, using <code>scale_brewer</code>.</p>
|
<p><code>scale_rsi_colours</code> sets colours to the bars: pastel blue for S, pastel turquoise for I and pastel red for R, using <code>scale_brewer</code>.</p>
|
||||||
<p><code>theme_rsi</code> is a <code>ggplot <a href='https://www.rdocumentation.org/packages/ggplot2/topics/theme'>theme</a></code> with minimal distraction.</p>
|
<p><code>theme_rsi</code> is a <code>ggplot <a href='https://www.rdocumentation.org/packages/ggplot2/topics/theme'>theme</a></code> with minimal distraction.</p>
|
||||||
<p><code>labels_rsi_count</code> print datalabels on the bars with percentage and amount of isolates using <code><a href='https://www.rdocumentation.org/packages/ggplot2/topics/geom_text'>geom_text</a></code></p>
|
<p><code>labels_rsi_count</code> print datalabels on the bars with percentage and amount of isolates using <code><a href='https://www.rdocumentation.org/packages/ggplot2/topics/geom_text'>geom_text</a></code></p>
|
||||||
<p><code>ggplot_rsi</code> is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (<code>%>%</code>). See Examples.</p>
|
<p><code>ggplot_rsi</code> is a wrapper around all above functions that uses data as first input. This makes it possible to use this function after a pipe (<code>%>%</code>). See Examples.</p>
|
||||||
@ -372,7 +401,7 @@
|
|||||||
<span class='fu'>geom_rsi</span>()
|
<span class='fu'>geom_rsi</span>()
|
||||||
|
|
||||||
<span class='co'># prettify the plot using some additional functions:</span>
|
<span class='co'># prettify the plot using some additional functions:</span>
|
||||||
<span class='no'>df</span> <span class='kw'><-</span> <span class='no'>septic_patients</span>[, <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/c'>c</a></span>(<span class='st'>"AMX"</span>, <span class='st'>"NIT"</span>, <span class='st'>"FOS"</span>, <span class='st'>"TMP"</span>, <span class='st'>"CIP"</span>)]
|
<span class='no'>df</span> <span class='kw'><-</span> <span class='no'>septic_patients</span> <span class='kw'>%>%</span> <span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>AMX</span>, <span class='no'>NIT</span>, <span class='no'>FOS</span>, <span class='no'>TMP</span>, <span class='no'>CIP</span>)
|
||||||
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/ggplot'>ggplot</a></span>(<span class='no'>df</span>) +
|
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/ggplot'>ggplot</a></span>(<span class='no'>df</span>) +
|
||||||
<span class='fu'>geom_rsi</span>() +
|
<span class='fu'>geom_rsi</span>() +
|
||||||
<span class='fu'>scale_y_percent</span>() +
|
<span class='fu'>scale_y_percent</span>() +
|
||||||
@ -399,6 +428,10 @@
|
|||||||
<span class='kw'>linetype</span> <span class='kw'>=</span> <span class='fl'>2</span>,
|
<span class='kw'>linetype</span> <span class='kw'>=</span> <span class='fl'>2</span>,
|
||||||
<span class='kw'>alpha</span> <span class='kw'>=</span> <span class='fl'>0.25</span>)
|
<span class='kw'>alpha</span> <span class='kw'>=</span> <span class='fl'>0.25</span>)
|
||||||
|
|
||||||
|
<span class='no'>septic_patients</span> <span class='kw'>%>%</span>
|
||||||
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>AMX</span>) <span class='kw'>%>%</span>
|
||||||
|
<span class='fu'>ggplot_rsi</span>(<span class='kw'>colours</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/c'>c</a></span>(<span class='kw'>SI</span> <span class='kw'>=</span> <span class='st'>"yellow"</span>))
|
||||||
|
|
||||||
<span class='co'># resistance of ciprofloxacine per age group</span>
|
<span class='co'># resistance of ciprofloxacine per age group</span>
|
||||||
<span class='no'>septic_patients</span> <span class='kw'>%>%</span>
|
<span class='no'>septic_patients</span> <span class='kw'>%>%</span>
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span>(<span class='kw'>first_isolate</span> <span class='kw'>=</span> <span class='fu'><a href='first_isolate.html'>first_isolate</a></span>(<span class='no'>.</span>)) <span class='kw'>%>%</span>
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span>(<span class='kw'>first_isolate</span> <span class='kw'>=</span> <span class='fu'><a href='first_isolate.html'>first_isolate</a></span>(<span class='no'>.</span>)) <span class='kw'>%>%</span>
|
||||||
@ -414,45 +447,45 @@
|
|||||||
<span class='no'>septic_patients</span> <span class='kw'>%>%</span>
|
<span class='no'>septic_patients</span> <span class='kw'>%>%</span>
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>AMX</span>, <span class='no'>NIT</span>, <span class='no'>FOS</span>, <span class='no'>TMP</span>, <span class='no'>CIP</span>) <span class='kw'>%>%</span>
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>AMX</span>, <span class='no'>NIT</span>, <span class='no'>FOS</span>, <span class='no'>TMP</span>, <span class='no'>CIP</span>) <span class='kw'>%>%</span>
|
||||||
<span class='fu'>ggplot_rsi</span>() + <span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/scale_viridis'>scale_fill_viridis_d</a></span>()
|
<span class='fu'>ggplot_rsi</span>() + <span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/scale_viridis'>scale_fill_viridis_d</a></span>()
|
||||||
|
<span class='co'># a shorter version which also adjusts data label colours:</span>
|
||||||
|
<span class='no'>septic_patients</span> <span class='kw'>%>%</span>
|
||||||
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>AMX</span>, <span class='no'>NIT</span>, <span class='no'>FOS</span>, <span class='no'>TMP</span>, <span class='no'>CIP</span>) <span class='kw'>%>%</span>
|
||||||
|
<span class='fu'>ggplot_rsi</span>(<span class='kw'>colours</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)
|
||||||
|
|
||||||
|
|
||||||
<span class='co'># it also supports groups (don't forget to use the group var on `x` or `facet`):</span>
|
<span class='co'># it also supports groups (don't forget to use the group var on `x` or `facet`):</span>
|
||||||
<span class='no'>septic_patients</span> <span class='kw'>%>%</span>
|
<span class='no'>septic_patients</span> <span class='kw'>%>%</span>
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>hospital_id</span>, <span class='no'>AMX</span>, <span class='no'>NIT</span>, <span class='no'>FOS</span>, <span class='no'>TMP</span>, <span class='no'>CIP</span>) <span class='kw'>%>%</span>
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>hospital_id</span>, <span class='no'>AMX</span>, <span class='no'>NIT</span>, <span class='no'>FOS</span>, <span class='no'>TMP</span>, <span class='no'>CIP</span>) <span class='kw'>%>%</span>
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%>%</span>
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>hospital_id</span>) <span class='kw'>%>%</span>
|
||||||
<span class='fu'>ggplot_rsi</span>(<span class='kw'>x</span> <span class='kw'>=</span> <span class='no'>hospital_id</span>,
|
<span class='fu'>ggplot_rsi</span>(<span class='kw'>x</span> <span class='kw'>=</span> <span class='st'>"hospital_id"</span>,
|
||||||
<span class='kw'>facet</span> <span class='kw'>=</span> <span class='no'>Antibiotic</span>,
|
<span class='kw'>facet</span> <span class='kw'>=</span> <span class='st'>"Antibiotic"</span>,
|
||||||
<span class='kw'>nrow</span> <span class='kw'>=</span> <span class='fl'>1</span>) +
|
<span class='kw'>nrow</span> <span class='kw'>=</span> <span class='fl'>1</span>,
|
||||||
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/labs'>labs</a></span>(<span class='kw'>title</span> <span class='kw'>=</span> <span class='st'>"AMR of Anti-UTI Drugs Per Hospital"</span>,
|
<span class='kw'>title</span> <span class='kw'>=</span> <span class='st'>"AMR of Anti-UTI Drugs Per Hospital"</span>,
|
||||||
<span class='kw'>x</span> <span class='kw'>=</span> <span class='st'>"Hospital"</span>)
|
<span class='kw'>x.title</span> <span class='kw'>=</span> <span class='st'>"Hospital"</span>,
|
||||||
|
<span class='kw'>datalabels</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)
|
||||||
|
|
||||||
<span class='co'># genuine analysis: check 2 most prevalent microorganisms</span>
|
<span class='co'># genuine analysis: check 3 most prevalent microorganisms</span>
|
||||||
<span class='no'>septic_patients</span> <span class='kw'>%>%</span>
|
<span class='no'>septic_patients</span> <span class='kw'>%>%</span>
|
||||||
<span class='co'># create new bacterial ID's, with all CoNS under the same group (Becker et al.)</span>
|
<span class='co'># create new bacterial ID's, with all CoNS under the same group (Becker et al.)</span>
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span>(<span class='kw'>mo</span> <span class='kw'>=</span> <span class='fu'><a href='as.mo.html'>as.mo</a></span>(<span class='no'>mo</span>, <span class='kw'>Becker</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)) <span class='kw'>%>%</span>
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span>(<span class='kw'>mo</span> <span class='kw'>=</span> <span class='fu'><a href='as.mo.html'>as.mo</a></span>(<span class='no'>mo</span>, <span class='kw'>Becker</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)) <span class='kw'>%>%</span>
|
||||||
<span class='co'># filter on top three bacterial ID's</span>
|
<span class='co'># filter on top three bacterial ID's</span>
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span>(<span class='no'>mo</span> <span class='kw'>%in%</span> <span class='fu'><a href='freq.html'>top_freq</a></span>(<span class='fu'><a href='freq.html'>freq</a></span>(<span class='no'>.</span>$<span class='no'>mo</span>), <span class='fl'>3</span>)) <span class='kw'>%>%</span>
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span>(<span class='no'>mo</span> <span class='kw'>%in%</span> <span class='fu'><a href='freq.html'>top_freq</a></span>(<span class='fu'><a href='freq.html'>freq</a></span>(<span class='no'>.</span>$<span class='no'>mo</span>), <span class='fl'>3</span>)) <span class='kw'>%>%</span>
|
||||||
<span class='co'># determine first isolates</span>
|
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span>(<span class='kw'>first_isolate</span> <span class='kw'>=</span> <span class='fu'><a href='first_isolate.html'>first_isolate</a></span>(<span class='no'>.</span>,
|
|
||||||
<span class='kw'>col_date</span> <span class='kw'>=</span> <span class='st'>"date"</span>,
|
|
||||||
<span class='kw'>col_patient_id</span> <span class='kw'>=</span> <span class='st'>"patient_id"</span>,
|
|
||||||
<span class='kw'>col_mo</span> <span class='kw'>=</span> <span class='st'>"mo"</span>)) <span class='kw'>%>%</span>
|
|
||||||
<span class='co'># filter on first isolates</span>
|
<span class='co'># filter on first isolates</span>
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/filter.html'>filter</a></span>(<span class='no'>first_isolate</span> <span class='kw'>==</span> <span class='fl'>TRUE</span>) <span class='kw'>%>%</span>
|
<span class='fu'><a href='first_isolate.html'>filter_first_isolate</a></span>() <span class='kw'>%>%</span>
|
||||||
<span class='co'># get short MO names (like "E. coli")</span>
|
<span class='co'># get short MO names (like "E. coli")</span>
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span>(<span class='kw'>mo</span> <span class='kw'>=</span> <span class='fu'><a href='mo_property.html'>mo_shortname</a></span>(<span class='no'>mo</span>, <span class='kw'>Becker</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)) <span class='kw'>%>%</span>
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span>(<span class='kw'>bug</span> <span class='kw'>=</span> <span class='fu'><a href='mo_property.html'>mo_shortname</a></span>(<span class='no'>mo</span>, <span class='kw'>Becker</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)) <span class='kw'>%>%</span>
|
||||||
<span class='co'># select this short name and some antiseptic drugs</span>
|
<span class='co'># select this short name and some antiseptic drugs</span>
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>mo</span>, <span class='no'>CXM</span>, <span class='no'>GEN</span>, <span class='no'>CIP</span>) <span class='kw'>%>%</span>
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span>(<span class='no'>bug</span>, <span class='no'>CXM</span>, <span class='no'>GEN</span>, <span class='no'>CIP</span>) <span class='kw'>%>%</span>
|
||||||
<span class='co'># group by MO</span>
|
<span class='co'># group by MO</span>
|
||||||
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>mo</span>) <span class='kw'>%>%</span>
|
<span class='fu'><a href='https://dplyr.tidyverse.org/reference/group_by.html'>group_by</a></span>(<span class='no'>bug</span>) <span class='kw'>%>%</span>
|
||||||
<span class='co'># plot the thing, putting MOs on the facet</span>
|
<span class='co'># plot the thing, putting MOs on the facet</span>
|
||||||
<span class='fu'>ggplot_rsi</span>(<span class='kw'>x</span> <span class='kw'>=</span> <span class='no'>Antibiotic</span>,
|
<span class='fu'>ggplot_rsi</span>(<span class='kw'>x</span> <span class='kw'>=</span> <span class='st'>"Antibiotic"</span>,
|
||||||
<span class='kw'>facet</span> <span class='kw'>=</span> <span class='no'>mo</span>,
|
<span class='kw'>facet</span> <span class='kw'>=</span> <span class='st'>"bug"</span>,
|
||||||
<span class='kw'>translate_ab</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
|
<span class='kw'>translate_ab</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
|
||||||
<span class='kw'>nrow</span> <span class='kw'>=</span> <span class='fl'>1</span>) +
|
<span class='kw'>nrow</span> <span class='kw'>=</span> <span class='fl'>1</span>,
|
||||||
<span class='fu'><a href='https://www.rdocumentation.org/packages/ggplot2/topics/labs'>labs</a></span>(<span class='kw'>title</span> <span class='kw'>=</span> <span class='st'>"AMR of Top Three Microorganisms In Blood Culture Isolates"</span>,
|
<span class='kw'>title</span> <span class='kw'>=</span> <span class='st'>"AMR of Top Three Microorganisms In Blood Culture Isolates"</span>,
|
||||||
<span class='kw'>subtitle</span> <span class='kw'>=</span> <span class='st'>"Only First Isolates, CoNS grouped according to Becker et al. (2014)"</span>,
|
<span class='kw'>subtitle</span> <span class='kw'>=</span> <span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/expression'>expression</a></span>(<span class='fu'><a href='https://www.rdocumentation.org/packages/base/topics/paste'>paste</a></span>(<span class='st'>"Only First Isolates, CoNS grouped according to Becker "</span>, <span class='fu'><a href='https://www.rdocumentation.org/packages/grDevices/topics/plotmath'>italic</a></span>(<span class='st'>"et al."</span>), <span class='st'>" (2014)"</span>)),
|
||||||
<span class='kw'>x</span> <span class='kw'>=</span> <span class='st'>"Microorganisms"</span>)
|
<span class='kw'>x.title</span> <span class='kw'>=</span> <span class='st'>"Antibiotic (Ears-Net code)"</span>)
|
||||||
<span class='co'># }</span></pre>
|
<span class='co'># }</span></pre>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
|
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="navbar-brand">
|
<span class="navbar-brand">
|
||||||
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
<a class="navbar-link" href="../index.html">AMR (for R)</a>
|
||||||
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9045</span>
|
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.1.9046</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -14,8 +14,11 @@ ggplot_rsi(data, position = NULL, x = "Antibiotic",
|
|||||||
fill = "Interpretation", facet = NULL, breaks = seq(0, 1, 0.1),
|
fill = "Interpretation", facet = NULL, breaks = seq(0, 1, 0.1),
|
||||||
limits = NULL, translate_ab = "name", combine_SI = TRUE,
|
limits = NULL, translate_ab = "name", combine_SI = TRUE,
|
||||||
combine_IR = FALSE, language = get_locale(), fun = count_df,
|
combine_IR = FALSE, language = get_locale(), fun = count_df,
|
||||||
nrow = NULL, datalabels = FALSE, datalabels.size = 3,
|
nrow = NULL, colours = c(S = "#61a8ff", SI = "#61a8ff", I =
|
||||||
datalabels.colour = "white", ...)
|
"#61f7ff", IR = "#ff6961", R = "#ff6961"), datalabels = TRUE,
|
||||||
|
datalabels.size = 2.5, datalabels.colour = "gray15", title = NULL,
|
||||||
|
subtitle = NULL, caption = NULL, x.title = NULL, y.title = NULL,
|
||||||
|
...)
|
||||||
|
|
||||||
geom_rsi(position = NULL, x = c("Antibiotic", "Interpretation"),
|
geom_rsi(position = NULL, x = c("Antibiotic", "Interpretation"),
|
||||||
fill = "Interpretation", translate_ab = "name",
|
fill = "Interpretation", translate_ab = "name",
|
||||||
@ -26,12 +29,14 @@ facet_rsi(facet = c("Interpretation", "Antibiotic"), nrow = NULL)
|
|||||||
|
|
||||||
scale_y_percent(breaks = seq(0, 1, 0.1), limits = NULL)
|
scale_y_percent(breaks = seq(0, 1, 0.1), limits = NULL)
|
||||||
|
|
||||||
scale_rsi_colours()
|
scale_rsi_colours(colours = c(S = "#61a8ff", SI = "#61a8ff", I =
|
||||||
|
"#61f7ff", IR = "#ff6961", R = "#ff6961"))
|
||||||
|
|
||||||
theme_rsi()
|
theme_rsi()
|
||||||
|
|
||||||
labels_rsi_count(position = NULL, x = "Antibiotic",
|
labels_rsi_count(position = NULL, x = "Antibiotic",
|
||||||
datalabels.size = 3, datalabels.colour = "white")
|
translate_ab = "name", combine_SI = TRUE, combine_IR = FALSE,
|
||||||
|
datalabels.size = 3, datalabels.colour = "gray15")
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{data}{a \code{data.frame} with column(s) of class \code{"rsi"} (see \code{\link{as.rsi}})}
|
\item{data}{a \code{data.frame} with column(s) of class \code{"rsi"} (see \code{\link{as.rsi}})}
|
||||||
@ -60,19 +65,31 @@ labels_rsi_count(position = NULL, x = "Antibiotic",
|
|||||||
|
|
||||||
\item{nrow}{(when using \code{facet}) number of rows}
|
\item{nrow}{(when using \code{facet}) number of rows}
|
||||||
|
|
||||||
\item{datalabels}{show datalabels using \code{labels_rsi_count}, will at default only be shown when \code{fun = count_df}}
|
\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} to use default \code{ggplot2} colours.}
|
||||||
|
|
||||||
|
\item{datalabels}{show datalabels using \code{labels_rsi_count}, will only be shown when \code{fun = count_df}}
|
||||||
|
|
||||||
\item{datalabels.size}{size of the datalabels}
|
\item{datalabels.size}{size of the datalabels}
|
||||||
|
|
||||||
\item{datalabels.colour}{colour of the datalabels}
|
\item{datalabels.colour}{colour of the datalabels}
|
||||||
|
|
||||||
|
\item{title}{text to show as title of the plot}
|
||||||
|
|
||||||
|
\item{subtitle}{text to show as subtitle of the plot}
|
||||||
|
|
||||||
|
\item{caption}{text to show as caption of the plot}
|
||||||
|
|
||||||
|
\item{x.title}{text to show as x axis description}
|
||||||
|
|
||||||
|
\item{y.title}{text to show as y axis description}
|
||||||
|
|
||||||
\item{...}{other parameters passed on to \code{geom_rsi}}
|
\item{...}{other parameters passed on to \code{geom_rsi}}
|
||||||
}
|
}
|
||||||
\description{
|
\description{
|
||||||
Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal \code{\link[ggplot2]{ggplot}} functions.
|
Use these functions to create bar plots for antimicrobial resistance analysis. All functions rely on internal \code{\link[ggplot2]{ggplot}2} functions.
|
||||||
}
|
}
|
||||||
\details{
|
\details{
|
||||||
At default, the names of antibiotics will be shown on the plots using \code{\link{ab_name}}. This can be set with the option \code{get_antibiotic_names} (a logical value), so change it e.g. to \code{FALSE} with \code{options(get_antibiotic_names = FALSE)}.
|
At default, the names of antibiotics will be shown on the plots using \code{\link{ab_name}}. This can be set with the \code{translate_ab} parameter. See \code{\link{count_df}}.
|
||||||
|
|
||||||
\strong{The functions}\cr
|
\strong{The functions}\cr
|
||||||
\code{geom_rsi} will take any variable from the data that has an \code{rsi} class (created with \code{\link{as.rsi}}) using \code{fun} (\code{\link{count_df}} at default, can also be \code{\link{portion_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.
|
\code{geom_rsi} will take any variable from the data that has an \code{rsi} class (created with \code{\link{as.rsi}}) using \code{fun} (\code{\link{count_df}} at default, can also be \code{\link{portion_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.
|
||||||
@ -81,7 +98,7 @@ At default, the names of antibiotics will be shown on the plots using \code{\lin
|
|||||||
|
|
||||||
\code{scale_y_percent} transforms the y axis to a 0 to 100\% range using \code{\link[ggplot2]{scale_continuous}}.
|
\code{scale_y_percent} transforms the y axis to a 0 to 100\% range using \code{\link[ggplot2]{scale_continuous}}.
|
||||||
|
|
||||||
\code{scale_rsi_colours} sets colours to the bars: green for S, yellow for I and red for R, using \code{\link[ggplot2]{scale_brewer}}.
|
\code{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_brewer}}.
|
||||||
|
|
||||||
\code{theme_rsi} is a \code{ggplot \link[ggplot2]{theme}} with minimal distraction.
|
\code{theme_rsi} is a \code{ggplot \link[ggplot2]{theme}} with minimal distraction.
|
||||||
|
|
||||||
@ -103,7 +120,7 @@ ggplot(septic_patients \%>\% select(AMX, NIT, FOS, TMP, CIP)) +
|
|||||||
geom_rsi()
|
geom_rsi()
|
||||||
|
|
||||||
# prettify the plot using some additional functions:
|
# prettify the plot using some additional functions:
|
||||||
df <- septic_patients[, c("AMX", "NIT", "FOS", "TMP", "CIP")]
|
df <- septic_patients \%>\% select(AMX, NIT, FOS, TMP, CIP)
|
||||||
ggplot(df) +
|
ggplot(df) +
|
||||||
geom_rsi() +
|
geom_rsi() +
|
||||||
scale_y_percent() +
|
scale_y_percent() +
|
||||||
@ -130,6 +147,10 @@ septic_patients \%>\%
|
|||||||
linetype = 2,
|
linetype = 2,
|
||||||
alpha = 0.25)
|
alpha = 0.25)
|
||||||
|
|
||||||
|
septic_patients \%>\%
|
||||||
|
select(AMX) \%>\%
|
||||||
|
ggplot_rsi(colours = c(SI = "yellow"))
|
||||||
|
|
||||||
# resistance of ciprofloxacine per age group
|
# resistance of ciprofloxacine per age group
|
||||||
septic_patients \%>\%
|
septic_patients \%>\%
|
||||||
mutate(first_isolate = first_isolate(.)) \%>\%
|
mutate(first_isolate = first_isolate(.)) \%>\%
|
||||||
@ -146,44 +167,44 @@ septic_patients \%>\%
|
|||||||
septic_patients \%>\%
|
septic_patients \%>\%
|
||||||
select(AMX, NIT, FOS, TMP, CIP) \%>\%
|
select(AMX, NIT, FOS, TMP, CIP) \%>\%
|
||||||
ggplot_rsi() + scale_fill_viridis_d()
|
ggplot_rsi() + scale_fill_viridis_d()
|
||||||
|
# a shorter version which also adjusts data label colours:
|
||||||
|
septic_patients \%>\%
|
||||||
|
select(AMX, NIT, FOS, TMP, CIP) \%>\%
|
||||||
|
ggplot_rsi(colours = FALSE)
|
||||||
|
|
||||||
|
|
||||||
# it also supports groups (don't forget to use the group var on `x` or `facet`):
|
# it also supports groups (don't forget to use the group var on `x` or `facet`):
|
||||||
septic_patients \%>\%
|
septic_patients \%>\%
|
||||||
select(hospital_id, AMX, NIT, FOS, TMP, CIP) \%>\%
|
select(hospital_id, AMX, NIT, FOS, TMP, CIP) \%>\%
|
||||||
group_by(hospital_id) \%>\%
|
group_by(hospital_id) \%>\%
|
||||||
ggplot_rsi(x = hospital_id,
|
ggplot_rsi(x = "hospital_id",
|
||||||
facet = Antibiotic,
|
facet = "Antibiotic",
|
||||||
nrow = 1) +
|
nrow = 1,
|
||||||
labs(title = "AMR of Anti-UTI Drugs Per Hospital",
|
title = "AMR of Anti-UTI Drugs Per Hospital",
|
||||||
x = "Hospital")
|
x.title = "Hospital",
|
||||||
|
datalabels = FALSE)
|
||||||
|
|
||||||
# genuine analysis: check 2 most prevalent microorganisms
|
# genuine analysis: check 3 most prevalent microorganisms
|
||||||
septic_patients \%>\%
|
septic_patients \%>\%
|
||||||
# create new bacterial ID's, with all CoNS under the same group (Becker et al.)
|
# create new bacterial ID's, with all CoNS under the same group (Becker et al.)
|
||||||
mutate(mo = as.mo(mo, Becker = TRUE)) \%>\%
|
mutate(mo = as.mo(mo, Becker = TRUE)) \%>\%
|
||||||
# filter on top three bacterial ID's
|
# filter on top three bacterial ID's
|
||||||
filter(mo \%in\% top_freq(freq(.$mo), 3)) \%>\%
|
filter(mo \%in\% top_freq(freq(.$mo), 3)) \%>\%
|
||||||
# determine first isolates
|
|
||||||
mutate(first_isolate = first_isolate(.,
|
|
||||||
col_date = "date",
|
|
||||||
col_patient_id = "patient_id",
|
|
||||||
col_mo = "mo")) \%>\%
|
|
||||||
# filter on first isolates
|
# filter on first isolates
|
||||||
filter(first_isolate == TRUE) \%>\%
|
filter_first_isolate() \%>\%
|
||||||
# get short MO names (like "E. coli")
|
# get short MO names (like "E. coli")
|
||||||
mutate(mo = mo_shortname(mo, Becker = TRUE)) \%>\%
|
mutate(bug = mo_shortname(mo, Becker = TRUE)) \%>\%
|
||||||
# select this short name and some antiseptic drugs
|
# select this short name and some antiseptic drugs
|
||||||
select(mo, CXM, GEN, CIP) \%>\%
|
select(bug, CXM, GEN, CIP) \%>\%
|
||||||
# group by MO
|
# group by MO
|
||||||
group_by(mo) \%>\%
|
group_by(bug) \%>\%
|
||||||
# plot the thing, putting MOs on the facet
|
# plot the thing, putting MOs on the facet
|
||||||
ggplot_rsi(x = Antibiotic,
|
ggplot_rsi(x = "Antibiotic",
|
||||||
facet = mo,
|
facet = "bug",
|
||||||
translate_ab = FALSE,
|
translate_ab = FALSE,
|
||||||
nrow = 1) +
|
nrow = 1,
|
||||||
labs(title = "AMR of Top Three Microorganisms In Blood Culture Isolates",
|
title = "AMR of Top Three Microorganisms In Blood Culture Isolates",
|
||||||
subtitle = "Only First Isolates, CoNS grouped according to Becker et al. (2014)",
|
subtitle = expression(paste("Only First Isolates, CoNS grouped according to Becker ", italic("et al."), " (2014)")),
|
||||||
x = "Microorganisms")
|
x.title = "Antibiotic (EARS-Net code)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,8 @@ test_that("frequency table works", {
|
|||||||
Sys.time() - runif(5, min = 0, max = 60 * 60 * 24),
|
Sys.time() - runif(5, min = 0, max = 60 * 60 * 24),
|
||||||
units = "hours")))))
|
units = "hours")))))
|
||||||
|
|
||||||
|
expect_output(print(freq(septic_patients$age)[,1:3]))
|
||||||
|
|
||||||
library(dplyr)
|
library(dplyr)
|
||||||
expect_output(septic_patients %>% select(1:2) %>% freq() %>% print())
|
expect_output(septic_patients %>% select(1:2) %>% freq() %>% print())
|
||||||
expect_output(septic_patients %>% select(1:3) %>% freq() %>% print())
|
expect_output(septic_patients %>% select(1:3) %>% freq() %>% print())
|
||||||
|
Loading…
Reference in New Issue
Block a user