From 46db3f7b13969e0eebe961860cf4051d7223c39a Mon Sep 17 00:00:00 2001 From: "Matthijs S. Berends" Date: Tue, 13 Mar 2018 15:40:10 +0100 Subject: [PATCH] import from graphics --- NAMESPACE | 2 ++ R/classes.R | 21 ++++++++++++--------- man/EUCAST.Rd | 51 ++++++++++++++++++++++++++++----------------------- man/as.rsi.Rd | 3 ++- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 76dccd3d..f87e4384 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -65,6 +65,8 @@ importFrom(dplyr,slice) importFrom(dplyr,summarise) importFrom(dplyr,tibble) importFrom(dplyr,vars) +importFrom(graphics,axis) +importFrom(graphics,barplot) importFrom(graphics,plot) importFrom(graphics,text) importFrom(reshape2,dcast) diff --git a/R/classes.R b/R/classes.R index 88db4caa..e33e9af3 100644 --- a/R/classes.R +++ b/R/classes.R @@ -28,7 +28,8 @@ #' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370))) #' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370), "A", "B", "C")) #' is.rsi(rsi_data) -#' plot(rsi_data) +#' plot(rsi_data) # for percentages +#' barplot(rsi_data) # for frequencies #' #' \donttest{ #' library(dplyr) @@ -166,17 +167,18 @@ plot.rsi <- function(x, ...) { #' @exportMethod barplot.rsi #' @export #' @importFrom dplyr %>% group_by summarise filter mutate if_else n_distinct -#' @importFrom graphics plot text +#' @importFrom graphics barplot axis #' @noRd -barplot.rsi <- function(x, ...) { - x_name <- deparse(substitute(x)) +barplot.rsi <- function(height, ...) { + x <- height + x_name <- deparse(substitute(height)) data <- data.frame(rsi = x, cnt = 1) %>% group_by(rsi) %>% summarise(cnt = sum(cnt)) %>% droplevels() - barplot(table(rsi_data), + barplot(table(x), col = c('green3', 'orange2', 'red3'), xlab = 'Antimicrobial Interpretation', main = paste('Susceptibilty Analysis of', x_name), @@ -395,13 +397,14 @@ plot.mic <- function(x, ...) { #' @exportMethod barplot.mic #' @export #' @importFrom dplyr %>% group_by summarise -#' @importFrom graphics plot text +#' @importFrom graphics barplot axis #' @noRd -barplot.mic <- function(x, ...) { - x_name <- deparse(substitute(x)) - create_barplot_mic(x, x_name, ...) +barplot.mic <- function(height, ...) { + x_name <- deparse(substitute(height)) + create_barplot_mic(height, x_name, ...) } +#' @importFrom graphics barplot axis create_barplot_mic <- function(x, x_name, ...) { data <- data.frame(mic = x, cnt = 1) %>% group_by(mic) %>% diff --git a/man/EUCAST.Rd b/man/EUCAST.Rd index 53c53106..ef9cb483 100644 --- a/man/EUCAST.Rd +++ b/man/EUCAST.Rd @@ -13,28 +13,29 @@ EUCAST Expert Rules Version 2.0: \cr \url{http://www.eucast.org/expert_rules_and_intrinsic_resistance} } \usage{ -EUCAST_rules(tbl, col_bactcode, info = TRUE, amcl = "amcl", amik = "amik", - amox = "amox", ampi = "ampi", azit = "azit", aztr = "aztr", - cefa = "cefa", cfra = "cfra", cfep = "cfep", cfot = "cfot", - cfox = "cfox", cfta = "cfta", cftr = "cftr", cfur = "cfur", - chlo = "chlo", cipr = "cipr", clar = "clar", clin = "clin", - clox = "clox", coli = "coli", czol = "czol", dapt = "dapt", - doxy = "doxy", erta = "erta", eryt = "eryt", fosf = "fosf", - fusi = "fusi", gent = "gent", imip = "imip", kana = "kana", - levo = "levo", linc = "linc", line = "line", mero = "mero", - mino = "mino", moxi = "moxi", nali = "nali", neom = "neom", - neti = "neti", nitr = "nitr", novo = "novo", norf = "norf", - oflo = "oflo", peni = "peni", pita = "pita", poly = "poly", - qida = "qida", rifa = "rifa", roxi = "roxi", siso = "siso", - teic = "teic", tetr = "tetr", tica = "tica", tige = "tige", - tobr = "tobr", trim = "trim", trsu = "trsu", vanc = "vanc") +EUCAST_rules(tbl, col_bactcode = "bactid", info = TRUE, amcl = "amcl", + amik = "amik", amox = "amox", ampi = "ampi", azit = "azit", + aztr = "aztr", cefa = "cefa", cfra = "cfra", cfep = "cfep", + cfot = "cfot", cfox = "cfox", cfta = "cfta", cftr = "cftr", + cfur = "cfur", chlo = "chlo", cipr = "cipr", clar = "clar", + clin = "clin", clox = "clox", coli = "coli", czol = "czol", + dapt = "dapt", doxy = "doxy", erta = "erta", eryt = "eryt", + fosf = "fosf", fusi = "fusi", gent = "gent", imip = "imip", + kana = "kana", levo = "levo", linc = "linc", line = "line", + mero = "mero", mino = "mino", moxi = "moxi", nali = "nali", + neom = "neom", neti = "neti", nitr = "nitr", novo = "novo", + norf = "norf", oflo = "oflo", peni = "peni", pita = "pita", + poly = "poly", qida = "qida", rifa = "rifa", roxi = "roxi", + siso = "siso", teic = "teic", tetr = "tetr", tica = "tica", + tige = "tige", tobr = "tobr", trim = "trim", trsu = "trsu", + vanc = "vanc") interpretive_reading(...) } \arguments{ \item{tbl}{table with antibiotic columns, like e.g. \code{amox} and \code{amcl}} -\item{col_bactcode}{column name of the bacteria ID in \code{tbl} - should also be present in \code{bactlist$bactid}, see \code{\link{bactlist}}.} +\item{col_bactcode}{column name of the bacteria ID in \code{tbl} - values of this column should be present in \code{bactlist$bactid}, see \code{\link{bactlist}}} \item{info}{print progress} @@ -49,15 +50,19 @@ table with edited variables of antibiotics. Apply expert rules (like intrinsic resistance), as defined by the European Committee on Antimicrobial Susceptibility Testing (EUCAST, \url{http://eucast.org}), see \emph{Source}. } \examples{ -a <- data.frame(bactid = c("STAAUR", "ESCCOL", "KLEPNE", "PSEAER"), - vanc = "-", - amox = "-", - coli = "-", - cfta = "-", - cfur = "-", +a <- data.frame(bactid = c("STAAUR", # Staphylococcus aureus + "ENCFAE", # Enterococcus faecalis + "ESCCOL", # Escherichia coli + "KLEPNE", # Klebsiella pneumoniae + "PSEAER"), # Pseudomonas aeruginosa + vanc = "-", # Vancomycin + amox = "-", # Amoxicillin + coli = "-", # Colistin + cfta = "-", # Ceftazidime + cfur = "-", # Cefuroxime stringsAsFactors = FALSE) a -b <- EUCAST_rules(a, "bactid") +b <- EUCAST_rules(a) b } diff --git a/man/as.rsi.Rd b/man/as.rsi.Rd index 64ff680b..01461007 100644 --- a/man/as.rsi.Rd +++ b/man/as.rsi.Rd @@ -22,7 +22,8 @@ This transforms a vector to a new class \code{rsi}, which is an ordered factor w rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370))) rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370), "A", "B", "C")) is.rsi(rsi_data) -plot(rsi_data) +plot(rsi_data) # for percentages +barplot(rsi_data) # for frequencies \donttest{ library(dplyr)