Browse Source

add barplots

main
parent
commit
04fc3573ec
No known key found for this signature in database
GPG Key ID: AE86720DBCDA4567
  1. 2
      DESCRIPTION
  2. 4
      NAMESPACE
  3. 70
      R/classes.R
  4. 28
      README.md
  5. 4
      man/ablist.Rd
  6. 3
      man/as.mic.Rd
  7. 6
      man/atc_property.Rd
  8. 2
      man/first_isolate.Rd

2
DESCRIPTION

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
Package: AMR
Version: 0.1.1
Date: 2018-02-26
Date: 2018-03-13
Title: Antimicrobial Resistance Analysis
Authors@R: c(
person(

4
NAMESPACE

@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
S3method(as.double,mic)
S3method(as.integer,mic)
S3method(as.numeric,mic)
S3method(barplot,mic)
S3method(barplot,rsi)
S3method(plot,mic)
S3method(plot,rsi)
S3method(print,mic)
@ -32,6 +34,8 @@ export(semi_join_bactlist) @@ -32,6 +34,8 @@ export(semi_join_bactlist)
exportMethods(as.double.mic)
exportMethods(as.integer.mic)
exportMethods(as.numeric.mic)
exportMethods(barplot.mic)
exportMethods(barplot.rsi)
exportMethods(plot.mic)
exportMethods(plot.rsi)
exportMethods(print.mic)

70
R/classes.R

@ -125,7 +125,7 @@ summary.rsi <- function(object, ...) { @@ -125,7 +125,7 @@ summary.rsi <- function(object, ...) {
#' @exportMethod plot.rsi
#' @export
#' @importFrom dplyr %>% group_by summarise filter mutate if_else
#' @importFrom dplyr %>% group_by summarise filter mutate if_else n_distinct
#' @importFrom graphics plot text
#' @noRd
plot.rsi <- function(x, ...) {
@ -150,12 +150,43 @@ plot.rsi <- function(x, ...) { @@ -150,12 +150,43 @@ plot.rsi <- function(x, ...) {
ylab = 'Percentage',
xlab = 'Antimicrobial Interpretation',
main = paste('Susceptibilty Analysis of', x_name),
axes = FALSE,
...)
# x axis
axis(side = 1, at = 1:n_distinct(data$x), labels = levels(data$x), lwd = 0)
# y axis, 0-100%
axis(side = 2, at = seq(0, 100, 5))
text(x = data$x,
y = data$s + 5,
y = data$s + 4,
labels = paste0(data$s, '% (n = ', data$n, ')'))
}
#' @exportMethod barplot.rsi
#' @export
#' @importFrom dplyr %>% group_by summarise filter mutate if_else n_distinct
#' @importFrom graphics plot text
#' @noRd
barplot.rsi <- function(x, ...) {
x_name <- deparse(substitute(x))
data <- data.frame(rsi = x, cnt = 1) %>%
group_by(rsi) %>%
summarise(cnt = sum(cnt)) %>%
droplevels()
barplot(table(rsi_data),
col = c('green3', 'orange2', 'red3'),
xlab = 'Antimicrobial Interpretation',
main = paste('Susceptibilty Analysis of', x_name),
ylab = 'Frequency',
axes = FALSE,
...)
# y axis, 0-100%
axis(side = 2, at = seq(0, max(data$cnt) + max(data$cnt) * 1.1, by = 25))
}
#' Class 'mic'
#'
#' This transforms a vector to a new class\code{mic}, which is an ordered factor with valid MIC values as levels. Invalid MIC values will be translated as \code{NA} with a warning.
@ -169,6 +200,7 @@ plot.rsi <- function(x, ...) { @@ -169,6 +200,7 @@ plot.rsi <- function(x, ...) {
#' mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16"))
#' is.mic(mic_data)
#' plot(mic_data)
#' barplot(mic_data)
#'
#' \donttest{
#' library(dplyr)
@ -357,21 +389,29 @@ summary.mic <- function(object, ...) { @@ -357,21 +389,29 @@ summary.mic <- function(object, ...) {
#' @noRd
plot.mic <- function(x, ...) {
x_name <- deparse(substitute(x))
create_barplot_mic(x, x_name, ...)
}
#' @exportMethod barplot.mic
#' @export
#' @importFrom dplyr %>% group_by summarise
#' @importFrom graphics plot text
#' @noRd
barplot.mic <- function(x, ...) {
x_name <- deparse(substitute(x))
create_barplot_mic(x, x_name, ...)
}
create_barplot_mic <- function(x, x_name, ...) {
data <- data.frame(mic = x, cnt = 1) %>%
group_by(mic) %>%
summarise(cnt = sum(cnt)) %>%
droplevels()
plot(x = data$mic,
y = data$cnt,
lwd = 2,
ylim = c(-0.5, max(5, max(data$cnt))),
ylab = 'Frequency',
xlab = 'MIC value',
main = paste('MIC values of', x_name),
...)
text(x = data$mic,
y = -0.5,
labels = paste('n =', data$cnt))
barplot(table(droplevels(x)),
ylab = 'Frequency',
xlab = 'MIC value',
main = paste('MIC values of', x_name),
axes = FALSE,
...)
axis(2, seq(0, max(data$cnt)))
}

28
README.md

@ -13,22 +13,26 @@ AMR can also be predicted for the forthcoming years with the `rsi_predict` funct @@ -13,22 +13,26 @@ AMR can also be predicted for the forthcoming years with the `rsi_predict` funct
It also contains functions to translate antibiotic codes from the lab (like `"AMOX"`) or the [WHO](https://www.whocc.no/atc_ddd_index/?code=J01CA04&showdescription=no) (like `"J01CA04"`) to trivial names (like `"amoxicillin"`) and vice versa.
## How to get it?
[![CRAN_Badge](http://www.r-pkg.org/badges/version/AMR)](http://cran.r-project.org/package=AMR)[![CRAN_Downloads](https://cranlogs.r-pkg.org/badges/grand-total/AMR)](http://cran.r-project.org/package=AMR)[![Travis_Build](https://travis-ci.org/msberends/AMR.svg?branch=master)](https://travis-ci.org/msberends/AMR)
This package is available on CRAN and also here on GitHub.
This package is available on CRAN (latest stable version) and also here on GitHub (latest development version).
### From CRAN (recommended, latest stable version)
[![CRAN_Badge](https://img.shields.io/cran/v/AMR.svg?label=CRAN&colorB=3679BC)](http://cran.r-project.org/package=AMR)
[![CRAN_Downloads](https://cranlogs.r-pkg.org/badges/grand-total/AMR)](http://cran.r-project.org/package=AMR)
### Latest stable version from CRAN (recommended)
For RStudio:
- Click on `Tools` and then `Install Packages...`
- Type in `AMR` and press <kbd>Install</kbd>
- RStudio:
- Click on `Tools` and then `Install Packages...`
- Type in `AMR` and press <kbd>Install</kbd>
Or in the R console:
```r
install.packages("AMR")
```
- R console:
- `install.packages("AMR")`
### From GitHub (latest development version)
[![Travis_Build](https://travis-ci.org/msberends/AMR.svg?branch=master)](https://travis-ci.org/msberends/AMR)
[![Since_Release](https://img.shields.io/github/commits-since/msberends/AMR/latest.svg?colorB=3679BC)](https://github.com/msberends/AMR/releases)
[![Last_Commit](https://img.shields.io/github/last-commit/msberends/AMR.svg?colorB=3679BC)](https://github.com/msberends/AMR/commits/master)
### Latest development version from GitHub
```r
install.packages("devtools")
devtools::install_github("msberends/AMR")
```
@ -155,6 +159,8 @@ bactlist # A tibble: 2,507 x 10 @@ -155,6 +159,8 @@ bactlist # A tibble: 2,507 x 10
<sup>2</sup> Department of Medical, Market and Innovation (MMI), Certe Medische diagnostiek & advies, Groningen, the Netherlands
## Copyright
[![License](https://img.shields.io/github/license/msberends/AMR.svg?colorB=3679BC)](https://github.com/msberends/AMR/blob/master/LICENSE)
This R package is licensed under the [GNU General Public License (GPL) v2.0](https://github.com/msberends/AMR/blob/master/LICENSE). In a nutshell, this means that this package:
- May be used for commercial purposes

4
man/ablist.Rd

@ -12,9 +12,9 @@ @@ -12,9 +12,9 @@
\item{\code{official}}{Official name by the WHO, like \code{"amoxicillin and enzyme inhibitor"}}
\item{\code{official_nl}}{Official name in the Netherlands, like \code{"Amoxicilline met enzymremmer"}}
\item{\code{trivial_nl}}{Trivial name in Dutch, like \code{"Amoxicilline/clavulaanzuur"}}
\item{\code{oral_ddd}}{Daily Defined Dose (DDD) according to the WHO, oral treatment}
\item{\code{oral_ddd}}{Defined Daily Dose (DDD) according to the WHO, oral treatment}
\item{\code{oral_units}}{Units of \code{ddd_units}}
\item{\code{iv_ddd}}{Daily Defined Dose (DDD) according to the WHO, parenteral treatment}
\item{\code{iv_ddd}}{Defined Daily Dose (DDD) according to the WHO, parenteral treatment}
\item{\code{iv_units}}{Units of \code{iv_ddd}}
\item{\code{atc_group1}}{ATC group in Dutch, like \code{"Macroliden, lincosamiden en streptograminen"}}
\item{\code{atc_group2}}{Subgroup of \code{atc_group1} in Dutch, like \code{"Macroliden"}}

3
man/as.mic.Rd

@ -18,12 +18,13 @@ is.mic(x) @@ -18,12 +18,13 @@ is.mic(x)
New class \code{mic}
}
\description{
This transforms a vector to a new class\code{mic}, which is an ordered factor valid MIC values as levels. Invalid MIC values will be translated as \code{NA} with a warning.
This transforms a vector to a new class\code{mic}, which is an ordered factor with valid MIC values as levels. Invalid MIC values will be translated as \code{NA} with a warning.
}
\examples{
mic_data <- as.mic(c(">=32", "1.0", "1", "1.00", 8, "<=0.128", "8", "16", "16"))
is.mic(mic_data)
plot(mic_data)
barplot(mic_data)
\donttest{
library(dplyr)

6
man/atc_property.Rd

@ -20,7 +20,7 @@ atc_property(atc_code, property, administration = "O", @@ -20,7 +20,7 @@ atc_property(atc_code, property, administration = "O",
\item{url}{url of website of the WHO. The sign \code{\%s} can be used as a placeholder for ATC codes.}
}
\description{
Gets data from the WHO to determine properties of an ATC of e.g. an antibiotic. \strong{This function requires an internet connection.}
Gets data from the WHO to determine properties of an ATC (e.g. an antibiotic) like name, defined daily dose (DDD) or standard unit. \strong{This function requires an internet connection.}
}
\details{
Abbreviations for the property \code{"Adm.R"} (parameter \code{administration}):
@ -51,7 +51,7 @@ Abbreviations for the property \code{"U"} (unit): @@ -51,7 +51,7 @@ Abbreviations for the property \code{"U"} (unit):
}
\examples{
\donttest{
atc_property("J01CA04", "DDD", "O") # oral DDD of amoxicillin
atc_property("J01CA04", "DDD", "P") # parenteral DDD of amoxicillin
atc_property("J01CA04", "DDD", "O") # oral DDD (Defined Daily Dose) of amoxicillin
atc_property("J01CA04", "DDD", "P") # parenteral DDD (Defined Daily Dose) of amoxicillin
}
}

2
man/first_isolate.Rd

@ -53,7 +53,7 @@ Determine first (weighted) isolates of all microorganisms of every patient per e @@ -53,7 +53,7 @@ Determine first (weighted) isolates of all microorganisms of every patient per e
\strong{Why this is so important} \cr
To conduct an analysis of antimicrobial resistance, you should only include the first isolate of every patient per episode \href{https://www.ncbi.nlm.nih.gov/pubmed/17304462}{[1]}. If you would not do this, you could easily get an overestimate or underestimate of the resistance of an antibiotic. Imagine that a patient was admitted with an MRSA and that it was found in 5 different blood cultures the following week. The resistance percentage of oxacillin of all \emph{S. aureus} isolates would be overestimated, because you included this MRSA more than once. It would be \href{https://en.wikipedia.org/wiki/Selection_bias}{selection bias}.
\strong{\code{points_threshold}} \cr
\strong{Using parameter \code{points_threshold}} \cr
To compare key antibiotics, the difference between antimicrobial interpretations will be measured. A difference from I to S|R (or vice versa) means 0.5 points. A difference from S to R (or vice versa) means 1 point. When the sum of points exceeds \code{points_threshold}, an isolate will be (re)selected as a first weighted isolate.
}
\examples{

Loading…
Cancel
Save