In the table above, all measurements are shown in milliseconds (thousands of seconds). A value of 5 milliseconds means it can determine 200 input values per second. It case of 200 milliseconds, this is only 5 input values per second. It is clear that accepted taxonomic names are extremely fast, but some variations are up to 200 times slower to determine.
To improve performance, we implemented two important algorithms to save unnecessary calculations: repetitive results and already precalculated results.
@@ -260,8 +260,8 @@ # what do these values look like? They are of class <mo>: head(x) # Class <mo> -# [1] B_STPHY_AURS B_STRPT_GRPC B_STPHY_CONS B_STPHY_EPDR B_STRPT_PNMN -# [6] B_PROTS_VLGR +# [1] B_ESCHR_COLI B_PROTS_MRBL B_PROTS_MRBL B_PROTS_MRBL B_STPHY_CONS +# [6] B_ENTRC # as the example_isolates data set has 2,000 rows, we should have 2 million items length(x) @@ -277,8 +277,8 @@ print(run_it, unit = "ms", signif = 3) # Unit: milliseconds # expr min lq mean median uq max neval -# mo_name(x) 157 187 222 206 224 372 10 -So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.206 seconds. That is 2.471 milliseconds per unique item on average. You only lose time on your unique input values.
+# mo_name(x) 160 189 224 201 228 356 10 +So getting official taxonomic names of 2,000,000 (!!) items consisting of 90 unique values only takes 0.201 seconds. That is 101 nanoseconds on average. You only lose time on your unique input values.
So going from mo_name("Staphylococcus aureus")
to "Staphylococcus aureus"
takes 0.0018 seconds - it doesn’t even start calculating if the result would be the same as the expected resulting value. That goes for all helper functions:
run_it <- microbenchmark(A = mo_species("aureus"),
@@ -309,14 +309,14 @@
print(run_it, unit = "ms", signif = 3)
# Unit: milliseconds
# expr min lq mean median uq max neval
-# A 1.44 1.72 1.69 1.74 1.75 1.78 10
-# B 1.47 1.55 1.67 1.73 1.74 1.89 10
-# C 1.52 1.59 1.73 1.74 1.89 1.91 10
-# D 1.46 1.51 1.64 1.64 1.75 1.89 10
-# E 1.42 1.47 1.60 1.52 1.71 1.97 10
-# F 1.44 1.71 1.69 1.72 1.75 1.88 10
-# G 1.42 1.50 1.68 1.61 1.73 2.36 10
-# H 1.52 1.54 1.66 1.71 1.73 1.87 10
Of course, when running mo_phylum("Firmicutes")
the function has zero knowledge about the actual microorganism, namely S. aureus. But since the result would be "Firmicutes"
anyway, there is no point in calculating the result. And because this package contains all phyla of all known bacteria, it can just return the initial value immediately.
Currently supported non-English languages are German, Dutch, Spanish, Italian, French and Portuguese.
diff --git a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png index f8429aaf..71a7c0cf 100644 Binary files a/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/benchmarks_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index 28653326..f038a464 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -81,7 +81,7 @@ diff --git a/docs/authors.html b/docs/authors.html index 245ceccf..5cb562e5 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -81,7 +81,7 @@ diff --git a/docs/index.html b/docs/index.html index 3689a9d8..b1bbcd3e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -43,7 +43,7 @@ diff --git a/docs/lifecycle_tidyverse.svg b/docs/lifecycle_tidyverse.svg index 2f5e2a96..1d8db94f 100644 --- a/docs/lifecycle_tidyverse.svg +++ b/docs/lifecycle_tidyverse.svg @@ -1,88 +1,32 @@ - + + diff --git a/docs/news/index.html b/docs/news/index.html index 5e1588e0..ee54c82c 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -81,7 +81,7 @@ @@ -236,13 +236,13 @@ Source:NEWS.md
- Support for custom MDRO guidelines, using the new custom_mdro_guideline()
function, please see mdro()
for additional info
Function isolate_identifier()
, which will paste a microorganism code with all antimicrobial results of a data set into one string for each row. This is useful to compare isolates, e.g. between institutions or regions, when there is no genotyping available.
ggplot()
generics for classes <mic>
and <disk>
Function mo_is_yeast()
, which determines whether a microorganism is a member of the taxonomic class Saccharomycetes or the taxonomic order Saccharomycetales:
@@ -321,7 +322,8 @@is.rsi.eligible()
now detects if the column name resembles an antibiotic name or code and now returnsTRUE
immediately if the input contains any of the values “R”, “S” or “I”. This drastically improves speed, also for a lot of other functions that rely on automatic determination of antibiotic columns.
get_episode()
and is_new_episode()
now support less than a day as value for argument episode_days
(e.g., to include one patient/test per hour)ampc_cephalosporin_resistance
in eucast_rules()
now also applies to value “I” (not only “S”)plot()
functions for classes <mic>
, <disk>
and <rsi>
- the former two now support colouring if you supply the microorganism and antimicrobial agentggplot_rsi()
and using plot()
on classes <mic>
, <disk>
and <rsi>
)print()
and summary()
on a Principal Components Analysis object (pca()
) now print additional group info if the original data was grouped using dplyr::group_by()
guess_ab_col()
. As this also internally improves the reliability of first_isolate()
and mdro()
, this might have a slight impact on the results of those functions.like()
function (and its fast alias %like%
) now always use Perl compatibility, improving speed for many functions in this package (e.g., as.mo()
is now up to 4 times faster)random_disk()
and random_mic()
now have an expanded range in their randomisationa named vector with colours for the bars. The names must be one or more of: S, SI, I, IR, R or be FALSE
to use default ggplot2 colours.
a named vector with colours for the bars. The names must be one or more of: S, SI, I, IR, R or be FALSE
for standard ggplot2 colours. The default colours are colour-blind friendly.
other arguments passed on to geom_rsi()
aesthetics to apply the colours to, defaults to "fill" but can also be "colour" or "both"
plot(<disk>)
plot(<mic>)
barplot(<mic>)
plot(<rsi>)
barplot(<rsi>)
plot(<mic>)
ggplot(<mic>)
plot(<disk>)
ggplot(<disk>)
plot(<rsi>)
Plotting for Classes rsi
, mic
and disk
Convenient wrapper around grep()
to match a pattern: x %like% pattern
. It always returns a logical
vector and is always case-insensitive (use x %like_case% pattern
for case-sensitive matching). Also, pattern
can be as long as x
to compare items of each index in both vectors, or they both can have the same length to iterate over all cases.
Convenient wrapper around grepl()
to match a pattern: x %like% pattern
. It always returns a logical
vector and is always case-insensitive (use x %like_case% pattern
for case-sensitive matching). Also, pattern
can be as long as x
to compare items of each index in both vectors, or they both can have the same length to iterate over all cases.
like(x, pattern, ignore.case = TRUE) @@ -295,7 +295,7 @@ The lifecycle of this function is stableOn our website https://msberends.github.io/AMR/ you can find a comprehensive tutorial about how to conduct AMR data analysis, the complete documentation of all functions and an example analysis using WHONET data. As we would like to better understand the backgrounds and needs of our users, please participate in our survey!See also
- +Examples
# simple test @@ -306,11 +306,15 @@ The lifecycle of this function is stableb %like% a #> FALSE -# also supports multiple patterns, length must be equal to x +# also supports multiple patterns a <- c("Test case", "Something different", "Yet another thing") b <- c( "case", "diff", "yet") a %like% b #> TRUE TRUE TRUE +a[1] %like% b +#> TRUE FALSE FALSE +a %like% b[1] +#> TRUE FALSE FALSE # get isolates whose name start with 'Ent' or 'ent' # \donttest{ diff --git a/docs/reference/plot.html b/docs/reference/plot.html index b71efe64..b7a1516b 100644 --- a/docs/reference/plot.html +++ b/docs/reference/plot.html @@ -49,7 +49,7 @@ - + @@ -82,7 +82,7 @@ @@ -234,65 +234,78 @@@@ -239,7 +239,7 @@Plotting for Classes
- Source:rsi
,mic
anddisk
R/amr.R
,R/disk.R
,R/mic.R
, and 1 more + Source:R/plot.R
plot.Rd
--Functions to print classes of the
+AMR
package.Functions to plot classes
rsi
,mic
anddisk
, with support for base R andggplot2
.# S3 method for disk -plot( - x, - main = paste("Disk zones values of", deparse(substitute(x))), - ylab = "Frequency", - xlab = "Disk diffusion (mm)", - axes = FALSE, - ... -) - -# S3 method for mic +# S3 method for mic plot( x, main = paste("MIC values of", deparse(substitute(x))), ylab = "Frequency", - xlab = "MIC value", - axes = FALSE, + xlab = "Minimum Inhibitory Concentration (mg/L)", + mo = NULL, + ab = NULL, + guideline = "EUCAST", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + expand = TRUE, ... ) # S3 method for mic -barplot( - height, - main = paste("MIC values of", deparse(substitute(height))), +ggplot( + data, + mapping = NULL, + title = paste("MIC values of", deparse(substitute(data))), ylab = "Frequency", - xlab = "MIC value", - axes = FALSE, + xlab = "Minimum Inhibitory Concentration (mg/L)", + mo = NULL, + ab = NULL, + guideline = "EUCAST", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + expand = TRUE, + ... +) + +# S3 method for disk +plot( + x, + main = paste("Disk zones values of", deparse(substitute(x))), + ylab = "Frequency", + xlab = "Disk diffusion diameter (mm)", + mo = NULL, + ab = NULL, + guideline = "EUCAST", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + expand = TRUE, + ... +) + +# S3 method for disk +ggplot( + data, + mapping = NULL, + title = paste("Disk zones values of", deparse(substitute(data))), + ylab = "Frequency", + xlab = "Disk diffusion diameter (mm)", + mo = NULL, + ab = NULL, + guideline = "EUCAST", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + expand = TRUE, ... ) # S3 method for rsi plot( x, - lwd = 2, - ylim = NULL, ylab = "Percentage", xlab = "Antimicrobial Interpretation", main = paste("Resistance Overview of", deparse(substitute(x))), - axes = FALSE, - ... -) - -# S3 method for rsi -barplot( - height, - col = c("chartreuse4", "chartreuse3", "brown3"), - xlab = ifelse(beside, "Antimicrobial Interpretation", ""), - main = paste("Resistance Overview of", deparse(substitute(height))), - ylab = "Frequency", - beside = TRUE, - axes = beside, ... )@@ -301,62 +314,53 @@x -+ the coordinates of points in the plot. Alternatively, a - single plotting structure, function or any R object with a -
plot
method can be provided.MIC values created with
as.mic()
or disk diffusion values created withas.disk()
- main -+ overall and sub title for the plot.
main, title +title of the plot
- ylab -+ a label for the y axis.
xlab, ylab +axis title
- xlab -+ a label for the x axis.
mo +any (vector of) text that can be coerced to a valid microorganism code with
as.mo()
- +axes -+ logical. If
TRUE
, a vertical (or horizontal, if -horiz
is true) axis is drawn.ab ++ any (vector of) text that can be coerced to a valid antimicrobial code with
as.ab()
+ +guideline ++ interpretation guideline to use, defaults to the latest included EUCAST guideline, see Details
+ +colours_RSI ++ colours to use for filling in the bars, must be a vector of three values (in the order R, S and I). The default colours are colour-blind friendly.
+ expand +logical to indicate whether the range on the x axis should be expanded between the lowest and highest value. For MIC values, intermediate values will be factors of 2 starting from the highest MIC value. For disk diameters, the whole diameter range will be filled.
... -+ Arguments passed on to functions
arguments passed on to
as.rsi()
- -height -- either a vector or matrix of values describing the - bars which make up the plot. If
height
is a vector, the - plot consists of a sequence of rectangular bars with heights - given by the values in the vector. Ifheight
is a matrix - andbeside
isFALSE
then each bar of the plot - corresponds to a column ofheight
, with the values in the - column giving the heights of stacked sub-bars making up the - bar. Ifheight
is a matrix andbeside
is -TRUE
, then the values in each column are juxtaposed - rather than stacked.- -ylim -- limits for the y axis.
- -col -- a vector of colors for the bars or bar components. - By default, grey is used if
height
is a vector, and a - gamma-corrected grey palette ifheight
is a matrix.- +beside -+ a logical value. If
FALSE
, the columns of -height
are portrayed as stacked bars, and ifTRUE
- the columns are portrayed as juxtaposed bars.mapping +aesthetic mappings to use for
ggplot()
Value
+ +The
+ggplot
functions return aggplot
model that is extendible with anyggplot2
function.Details
+ +For interpreting MIC values as well as disk diffusion diameters, supported guidelines to be used as input for the
+guideline
argument are: "EUCAST 2021", "EUCAST 2020", "EUCAST 2019", "EUCAST 2018", "EUCAST 2017", "EUCAST 2016", "EUCAST 2015", "EUCAST 2014", "EUCAST 2013", "EUCAST 2012", "EUCAST 2011", "CLSI 2019", "CLSI 2018", "CLSI 2017", "CLSI 2016", "CLSI 2015", "CLSI 2014", "CLSI 2013", "CLSI 2012", "CLSI 2011" and "CLSI 2010".Simply using
"CLSI"
or"EUCAST"
as input will automatically select the latest version of that guideline.Stable Lifecycle
@@ -370,6 +374,22 @@ The lifecycle of this function is stableOn our website https://msberends.github.io/AMR/ you can find a comprehensive tutorial about how to conduct AMR data analysis, the complete documentation of all functions and an example analysis using WHONET data. As we would like to better understand the backgrounds and needs of our users, please participate in our survey! +Examples
+some_mic_values <- random_mic(size = 100) +some_disk_values <- random_disk(size = 100, mo = "Escherichia coli", ab = "cipro") + +plot(some_mic_values) +plot(some_disk_values) + +# when providing the microorganism and antibiotic, colours will show interpretations: +plot(some_mic_values, mo = "S. aureus", ab = "ampicillin") +plot(some_disk_values, mo = "Escherichia coli", ab = "cipro") + +if (require("ggplot2")) { + ggplot(some_mic_values) + ggplot(some_disk_values, mo = "Escherichia coli", ab = "cipro") +} +-These functions can be used for generating random MIC values and disk diffusion diameters, for AMR data analysis practice.
+These functions can be used for generating random MIC values and disk diffusion diameters, for AMR data analysis practice. By providing a microorganism and antimicrobial agent, the generated results will reflect reality as much as possible.
random_mic(size, mo = NULL, ab = NULL, ...) diff --git a/docs/survey.html b/docs/survey.html index 51aec706..5ec1ebb2 100644 --- a/docs/survey.html +++ b/docs/survey.html @@ -81,7 +81,7 @@ diff --git a/man/as.mic.Rd b/man/as.mic.Rd index 38de5a8e..77ec57f6 100755 --- a/man/as.mic.Rd +++ b/man/as.mic.Rd @@ -54,8 +54,9 @@ as.rsi(x = as.mic(4), ab = "AMX", guideline = "EUCAST") +# plot MIC values, see ?plot plot(mic_data) -barplot(mic_data) +plot(mic_data, mo = "E. coli", ab = "cipro") } \seealso{ \code{\link[=as.rsi]{as.rsi()}} diff --git a/man/figures/lifecycle_tidyverse.svg b/man/figures/lifecycle_tidyverse.svg index 2f5e2a96..1d8db94f 100644 --- a/man/figures/lifecycle_tidyverse.svg +++ b/man/figures/lifecycle_tidyverse.svg @@ -1,88 +1,32 @@ - + + diff --git a/man/ggplot_rsi.Rd b/man/ggplot_rsi.Rd index 4e508790..4eb27701 100644 --- a/man/ggplot_rsi.Rd +++ b/man/ggplot_rsi.Rd @@ -54,8 +54,9 @@ facet_rsi(facet = c("interpretation", "antibiotic"), nrow = NULL) scale_y_percent(breaks = seq(0, 1, 0.1), limits = NULL) scale_rsi_colours( - colours = c(S = "#61a8ff", SI = "#61a8ff", I = "#61f7ff", IR = "#ff6961", R = - "#ff6961") + colours = c(S = "#3CAEA3", SI = "#3CAEA3", I = "#F6D55C", IR = "#ED553B", R = + "#ED553B"), + aesthetics = "fill" ) theme_rsi() @@ -99,7 +100,7 @@ labels_rsi_count( \item{nrow}{(when using \code{facet}) number of rows} -\item{colours}{a named vector with colours for the bars. The names must be one or more of: S, SI, I, IR, R or be \code{FALSE} to use default \link[ggplot2:ggplot]{ggplot2} colours.} +\item{colours}{a named vector with colours for the bars. The names must be one or more of: S, SI, I, IR, R or be \code{FALSE} for standard \link[ggplot2:ggplot]{ggplot2} colours. The default colours are colour-blind friendly.} \item{datalabels}{show datalabels using \code{\link[=labels_rsi_count]{labels_rsi_count()}}} @@ -118,6 +119,8 @@ labels_rsi_count( \item{y.title}{text to show as y axis description} \item{...}{other arguments passed on to \code{\link[=geom_rsi]{geom_rsi()}}} + +\item{aesthetics}{aesthetics to apply the colours to, defaults to "fill" but can also be "colour" or "both"} } \description{ Use these functions to create bar plots for AMR data analysis. All functions rely on \link[ggplot2:ggplot]{ggplot2} functions. diff --git a/man/like.Rd b/man/like.Rd index 4a5df368..e752f060 100755 --- a/man/like.Rd +++ b/man/like.Rd @@ -26,7 +26,7 @@ x \%like_case\% pattern A \code{\link{logical}} vector } \description{ -Convenient wrapper around \code{\link[=grep]{grep()}} to match a pattern: \code{x \%like\% pattern}. It always returns a \code{\link{logical}} vector and is always case-insensitive (use \code{x \%like_case\% pattern} for case-sensitive matching). Also, \code{pattern} can be as long as \code{x} to compare items of each index in both vectors, or they both can have the same length to iterate over all cases. +Convenient wrapper around \code{\link[=grepl]{grepl()}} to match a pattern: \code{x \%like\% pattern}. It always returns a \code{\link{logical}} vector and is always case-insensitive (use \code{x \%like_case\% pattern} for case-sensitive matching). Also, \code{pattern} can be as long as \code{x} to compare items of each index in both vectors, or they both can have the same length to iterate over all cases. } \details{ The \verb{\%like\%} function: @@ -61,11 +61,15 @@ a \%like\% b b \%like\% a #> FALSE -# also supports multiple patterns, length must be equal to x +# also supports multiple patterns a <- c("Test case", "Something different", "Yet another thing") b <- c( "case", "diff", "yet") a \%like\% b #> TRUE TRUE TRUE +a[1] \%like\% b +#> TRUE FALSE FALSE +a \%like\% b[1] +#> TRUE FALSE FALSE # get isolates whose name start with 'Ent' or 'ent' \donttest{ @@ -76,5 +80,5 @@ if (require("dplyr")) { } } \seealso{ -\code{\link[=grep]{grep()}} +\code{\link[=grepl]{grepl()}} } diff --git a/man/plot.Rd b/man/plot.Rd index 3fe2ea64..11eedbdf 100644 --- a/man/plot.Rd +++ b/man/plot.Rd @@ -1,102 +1,107 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/amr.R, R/disk.R, R/mic.R, R/rsi.R +% Please edit documentation in R/plot.R \name{plot} \alias{plot} -\alias{plot.disk} \alias{plot.mic} -\alias{barplot.mic} +\alias{ggplot.mic} +\alias{plot.disk} +\alias{ggplot.disk} \alias{plot.rsi} -\alias{barplot.rsi} \title{Plotting for Classes \code{rsi}, \code{mic} and \code{disk}} \usage{ -\method{plot}{disk}( - x, - main = paste("Disk zones values of", deparse(substitute(x))), - ylab = "Frequency", - xlab = "Disk diffusion (mm)", - axes = FALSE, - ... -) - \method{plot}{mic}( x, main = paste("MIC values of", deparse(substitute(x))), ylab = "Frequency", - xlab = "MIC value", - axes = FALSE, + xlab = "Minimum Inhibitory Concentration (mg/L)", + mo = NULL, + ab = NULL, + guideline = "EUCAST", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + expand = TRUE, ... ) -\method{barplot}{mic}( - height, - main = paste("MIC values of", deparse(substitute(height))), +\method{ggplot}{mic}( + data, + mapping = NULL, + title = paste("MIC values of", deparse(substitute(data))), ylab = "Frequency", - xlab = "MIC value", - axes = FALSE, + xlab = "Minimum Inhibitory Concentration (mg/L)", + mo = NULL, + ab = NULL, + guideline = "EUCAST", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + expand = TRUE, + ... +) + +\method{plot}{disk}( + x, + main = paste("Disk zones values of", deparse(substitute(x))), + ylab = "Frequency", + xlab = "Disk diffusion diameter (mm)", + mo = NULL, + ab = NULL, + guideline = "EUCAST", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + expand = TRUE, + ... +) + +\method{ggplot}{disk}( + data, + mapping = NULL, + title = paste("Disk zones values of", deparse(substitute(data))), + ylab = "Frequency", + xlab = "Disk diffusion diameter (mm)", + mo = NULL, + ab = NULL, + guideline = "EUCAST", + colours_RSI = c("#ED553B", "#3CAEA3", "#F6D55C"), + expand = TRUE, ... ) \method{plot}{rsi}( x, - lwd = 2, - ylim = NULL, ylab = "Percentage", xlab = "Antimicrobial Interpretation", main = paste("Resistance Overview of", deparse(substitute(x))), - axes = FALSE, - ... -) - -\method{barplot}{rsi}( - height, - col = c("chartreuse4", "chartreuse3", "brown3"), - xlab = ifelse(beside, "Antimicrobial Interpretation", ""), - main = paste("Resistance Overview of", deparse(substitute(height))), - ylab = "Frequency", - beside = TRUE, - axes = beside, ... ) } \arguments{ -\item{x}{the coordinates of points in the plot. Alternatively, a - single plotting structure, function or \emph{any \R object with a - \code{plot} method} can be provided.} +\item{x}{MIC values created with \code{\link[=as.mic]{as.mic()}} or disk diffusion values created with \code{\link[=as.disk]{as.disk()}}} -\item{main}{overall and sub title for the plot.} +\item{main, title}{title of the plot} -\item{ylab}{a label for the y axis.} +\item{xlab, ylab}{axis title} -\item{xlab}{a label for the x axis.} +\item{mo}{any (vector of) text that can be coerced to a valid microorganism code with \code{\link[=as.mo]{as.mo()}}} -\item{axes}{logical. If \code{TRUE}, a vertical (or horizontal, if - \code{horiz} is true) axis is drawn.} +\item{ab}{any (vector of) text that can be coerced to a valid antimicrobial code with \code{\link[=as.ab]{as.ab()}}} -\item{...}{Arguments passed on to functions} +\item{guideline}{interpretation guideline to use, defaults to the latest included EUCAST guideline, see \emph{Details}} -\item{height}{either a vector or matrix of values describing the - bars which make up the plot. If \code{height} is a vector, the - plot consists of a sequence of rectangular bars with heights - given by the values in the vector. If \code{height} is a matrix - and \code{beside} is \code{FALSE} then each bar of the plot - corresponds to a column of \code{height}, with the values in the - column giving the heights of stacked sub-bars making up the - bar. If \code{height} is a matrix and \code{beside} is - \code{TRUE}, then the values in each column are juxtaposed - rather than stacked.} +\item{colours_RSI}{colours to use for filling in the bars, must be a vector of three values (in the order R, S and I). The default colours are colour-blind friendly.} -\item{ylim}{limits for the y axis.} +\item{expand}{logical to indicate whether the range on the x axis should be expanded between the lowest and highest value. For MIC values, intermediate values will be factors of 2 starting from the highest MIC value. For disk diameters, the whole diameter range will be filled.} -\item{col}{a vector of colors for the bars or bar components. - By default, grey is used if \code{height} is a vector, and a - gamma-corrected grey palette if \code{height} is a matrix.} +\item{...}{arguments passed on to \code{\link[=as.rsi]{as.rsi()}}} -\item{beside}{a logical value. If \code{FALSE}, the columns of - \code{height} are portrayed as stacked bars, and if \code{TRUE} - the columns are portrayed as juxtaposed bars.} +\item{mapping}{aesthetic mappings to use for \code{\link[ggplot2:ggplot]{ggplot()}}} +} +\value{ +The \code{ggplot} functions return a \code{\link[ggplot2:ggplot]{ggplot}} model that is extendible with any \code{ggplot2} function. } \description{ -Functions to print classes of the \code{AMR} package. +Functions to plot classes \code{rsi}, \code{mic} and \code{disk}, with support for base R and \code{ggplot2}. +} +\details{ +For interpreting MIC values as well as disk diffusion diameters, supported guidelines to be used as input for the \code{guideline} argument are: "EUCAST 2021", "EUCAST 2020", "EUCAST 2019", "EUCAST 2018", "EUCAST 2017", "EUCAST 2016", "EUCAST 2015", "EUCAST 2014", "EUCAST 2013", "EUCAST 2012", "EUCAST 2011", "CLSI 2019", "CLSI 2018", "CLSI 2017", "CLSI 2016", "CLSI 2015", "CLSI 2014", "CLSI 2013", "CLSI 2012", "CLSI 2011" and "CLSI 2010". + +Simply using \code{"CLSI"} or \code{"EUCAST"} as input will automatically select the latest version of that guideline. } \section{Stable Lifecycle}{ @@ -111,4 +116,19 @@ If the unlying code needs breaking changes, they will occur gradually. For examp On our website \url{https://msberends.github.io/AMR/} you can find \href{https://msberends.github.io/AMR/articles/AMR.html}{a comprehensive tutorial} about how to conduct AMR data analysis, the \href{https://msberends.github.io/AMR/reference/}{complete documentation of all functions} and \href{https://msberends.github.io/AMR/articles/WHONET.html}{an example analysis using WHONET data}. As we would like to better understand the backgrounds and needs of our users, please \href{https://msberends.github.io/AMR/survey.html}{participate in our survey}! } -\keyword{internal} +\examples{ +some_mic_values <- random_mic(size = 100) +some_disk_values <- random_disk(size = 100, mo = "Escherichia coli", ab = "cipro") + +plot(some_mic_values) +plot(some_disk_values) + +# when providing the microorganism and antibiotic, colours will show interpretations: +plot(some_mic_values, mo = "S. aureus", ab = "ampicillin") +plot(some_disk_values, mo = "Escherichia coli", ab = "cipro") + +if (require("ggplot2")) { + ggplot(some_mic_values) + ggplot(some_disk_values, mo = "Escherichia coli", ab = "cipro") +} +} diff --git a/man/random.Rd b/man/random.Rd index 1a6f190a..5776869a 100644 --- a/man/random.Rd +++ b/man/random.Rd @@ -28,7 +28,7 @@ random_rsi(size, prob_RSI = c(0.33, 0.33, 0.33), ...) class \verb{} for \code{\link[=random_mic]{random_mic()}} (see \code{\link[=as.mic]{as.mic()}}) and class \verb{ } for \code{\link[=random_disk]{random_disk()}} (see \code{\link[=as.disk]{as.disk()}}) } \description{ -These functions can be used for generating random MIC values and disk diffusion diameters, for AMR data analysis practice. +These functions can be used for generating random MIC values and disk diffusion diameters, for AMR data analysis practice. By providing a microorganism and antimicrobial agent, the generated results will reflect reality as much as possible. } \details{ The base R function \code{\link[=sample]{sample()}} is used for generating values. diff --git a/pkgdown/logos/lifecycle_tidyverse.svg b/pkgdown/logos/lifecycle_tidyverse.svg index 2f5e2a96..1d8db94f 100644 --- a/pkgdown/logos/lifecycle_tidyverse.svg +++ b/pkgdown/logos/lifecycle_tidyverse.svg @@ -1,88 +1,32 @@ - + + diff --git a/tests/testthat/test-disk.R b/tests/testthat/test-disk.R index 0ae02be9..9eef32b9 100755 --- a/tests/testthat/test-disk.R +++ b/tests/testthat/test-disk.R @@ -43,9 +43,17 @@ test_that("disk works", { expect_s3_class(x, "disk") pdf(NULL) # prevent Rplots.pdf being created + expect_silent(barplot(as.disk(c(10, 20, 40)))) expect_silent(plot(as.disk(c(10, 20, 40)))) - + expect_silent(plot(as.disk(c(10, 20, 40)), expand = FALSE)) + expect_silent(plot(as.disk(c(10, 20, 40)), mo = "esco", ab = "cipr")) + if (require("ggplot2")) { + expect_s3_class(ggplot(as.disk(c(10, 20, 40))), "gg") + expect_s3_class(ggplot(as.disk(c(10, 20, 40)), expand = FALSE), "gg") + expect_s3_class(ggplot(as.disk(c(10, 20, 40)), mo = "esco", ab = "cipr"), "gg") + } expect_output(print(as.disk(12))) + library(dplyr, warn.conflicts = FALSE) expect_output(print(tibble(d = as.disk(12)))) diff --git a/tests/testthat/test-mic.R b/tests/testthat/test-mic.R index fb5be9ac..a30fefbf 100755 --- a/tests/testthat/test-mic.R +++ b/tests/testthat/test-mic.R @@ -51,6 +51,13 @@ test_that("mic works", { pdf(NULL) # prevent Rplots.pdf being created expect_silent(barplot(as.mic(c(1, 2, 4, 8)))) expect_silent(plot(as.mic(c(1, 2, 4, 8)))) + expect_silent(plot(as.mic(c(1, 2, 4, 8)), expand = FALSE)) + expect_silent(plot(as.mic(c(1, 2, 4, 8)), mo = "esco", ab = "cipr")) + if (require("ggplot2")) { + expect_s3_class(ggplot(as.mic(c(1, 2, 4, 8))), "gg") + expect_s3_class(ggplot(as.mic(c(1, 2, 4, 8)), expand = FALSE), "gg") + expect_s3_class(ggplot(as.mic(c(1, 2, 4, 8, 32)), mo = "esco", ab = "cipr"), "gg") + } expect_output(print(as.mic(c(1, 2, 4, 8)))) expect_equal(summary(as.mic(c(2, 8))), diff --git a/vignettes/benchmarks.Rmd b/vignettes/benchmarks.Rmd index b5b56810..c79e2722 100755 --- a/vignettes/benchmarks.Rmd +++ b/vignettes/benchmarks.Rmd @@ -117,7 +117,7 @@ run_it <- microbenchmark(mo_name(x), print(run_it, unit = "ms", signif = 3) ``` -So getting official taxonomic names of `r format(length(x), big.mark = ",")` (!!) items consisting of `r n_distinct(x)` unique values only takes `r round(median(run_it$time, na.rm = TRUE) / 1e9, 3)` seconds. That is `r round(mean(run_it$time, na.rm = TRUE) / 1e6 / n_distinct(x), 3)` milliseconds per unique item on average. You only lose time on your unique input values. +So getting official taxonomic names of `r format(length(x), big.mark = ",")` (!!) items consisting of `r n_distinct(x)` unique values only takes `r round(median(run_it$time, na.rm = TRUE) / 1e9, 3)` seconds. That is `r round(median(run_it$time, na.rm = TRUE) / length(x), 0)` nanoseconds on average. You only lose time on your unique input values. ### Precalculated results