1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 22:22:03 +02:00

(v1.5.0.9025) big plot and ggplot generics update

This commit is contained in:
2021-02-25 10:33:08 +01:00
parent 31ceba5441
commit a673407904
42 changed files with 1058 additions and 842 deletions

View File

@ -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()}}

View File

@ -1,88 +1,32 @@
<?xml version="1.0"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg
xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink"
version="1.1" viewBox="8 48 787 198" width="787pt" height="198pt"><metadata
xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:date>2018-01-05
19:43Z</dc:date><!-- Produced by OmniGraffle Professional 5.4.4
--></metadata><defs><font-face font-family="Helvetica Neue" font-size="16"
panose-1="2 0 5 3 0 0 0 2 0 4" units-per-em="1000" underline-position="-100"
underline-thickness="50" slope="0" x-height="517" cap-height="714"
ascent="951.99585" descent="-212.99744"
font-weight="500"><font-face-src><font-face-name
name="HelveticaNeue"/></font-face-src></font-face><marker orient="auto"
overflow="visible" markerUnits="strokeWidth" id="FilledArrow_Marker" viewBox="-1
-4 10 8" markerWidth="10" markerHeight="8" color="black"><g><path d="M 8 0 L 0
-3 L 0 3 Z" fill="currentColor" stroke="currentColor"
stroke-width="1"/></g></marker></defs><g stroke="none" stroke-opacity="1"
stroke-dasharray="none" fill="none" fill-opacity="1"><title>Canvas
1</title><rect fill="white" width="805.88977"
height="536.27556"/><g><title>Layer 1</title><rect x="201.43709" y="148.91563"
width="88.865815" height="36.026683" stroke="#0080ff" stroke-linecap="round"
stroke-linejoin="round" stroke-width="2"/><text transform="translate(206.43709
157.70498)" fill="black"><tspan font-family="Helvetica Neue" font-size="16"
font-weight="500" x="7.8649073" y="15"
textLength="63.136">maturing</tspan></text><rect x="10.4153" y="97.854194"
width="123.69161" height="36.026683" stroke="#ff8000" stroke-linecap="round"
stroke-linejoin="round" stroke-width="2"/><text transform="translate(15.4153
106.643536)" fill="black"><tspan font-family="Helvetica Neue" font-size="16"
font-weight="500" x="10.7658034" y="15"
textLength="92.160004">experimental</tspan></text><rect x="339.64294"
y="207.75286" width="64.848027" height="36.026683" stroke="green"
stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/><text
transform="translate(344.64294 216.5422)" fill="black"><tspan
font-family="Helvetica Neue" font-size="16" font-weight="500" x="5.7920134"
y="15" textLength="43.264">stable</tspan></text><rect x="613.9284" y="118.27877"
width="67.249806" height="36.026683" stroke="#ff8000" stroke-linecap="round"
stroke-linejoin="round" stroke-width="2"/><text transform="translate(618.9284
127.06811)" fill="black"><tspan font-family="Helvetica Neue" font-size="16"
font-weight="500" x="5.9529028" y="15" textLength="5.328">r</tspan><tspan
font-family="Helvetica Neue" font-size="16" font-weight="500" x="10.992903"
y="15" textLength="22.511999">etir</tspan><tspan font-family="Helvetica Neue"
font-size="16" font-weight="500" x="33.216903" y="15"
textLength="18.08">ed</tspan></text><rect x="325.78587" y="50.19685"
width="85.263146" height="36.026683" stroke="#0080ff" stroke-linecap="round"
stroke-linejoin="round" stroke-width="2"/><text transform="translate(330.78587
58.986193)" fill="black"><tspan font-family="Helvetica Neue" font-size="16"
font-weight="500" x="7.543573" y="15"
textLength="60.176">dormant</tspan></text><rect x="468.56405" y="142.10744"
width="112.8836" height="36.026683" stroke="#0080ff" stroke-linecap="round"
stroke-linejoin="round" stroke-width="2"/><text transform="translate(473.56405
150.89678)" fill="black"><tspan font-family="Helvetica Neue" font-size="16"
font-weight="500" x="9.801801" y="15"
textLength="83.28">questioning</tspan></text><line x1="135.106906"
y1="134.351596" x2="190.93937" y2="150.77291"
marker-end="url(#FilledArrow_Marker)" stroke="black" stroke-linecap="round"
stroke-linejoin="round" stroke-width="1"/><line x1="286.65074" y1="185.94232"
x2="329.67024" y2="205.99944" marker-end="url(#FilledArrow_Marker)"
stroke="black" stroke-linecap="round" stroke-linejoin="round"
stroke-width="1"/><path d="M 379.93472 206.75285 C 387.55754 192.63012 401.66897
174.0594 426.21202 163.52488 C 436.33446 159.18006 447.11932 156.67954 457.70464
155.39871" marker-end="url(#FilledArrow_Marker)" stroke="black"
stroke-linecap="round" stroke-linejoin="round" stroke-width="1"/><line
x1="582.44766" y1="148.95154" x2="603.2104" y2="144.91434"
marker-end="url(#FilledArrow_Marker)" stroke="black" stroke-linecap="round"
stroke-linejoin="round" stroke-width="1"/><path d="M 501.44774 179.13413 C
487.32306 189.48841 467.98586 202.01855 446.6366 211.18222 C 435.19097 216.09499
424.5888 219.42992 415.18313 221.6778" marker-end="url(#FilledArrow_Marker)"
stroke="black" stroke-linecap="round" stroke-linejoin="round"
stroke-width="1"/><path d="M 412.04903 66.0841 C 438.72737 66.23414 475.24547
68.794908 514.7185 78.42248 C 552.22946 87.57149 584.04206 101.061534 607.12235
112.71587" marker-end="url(#FilledArrow_Marker)" stroke="black"
stroke-linecap="round" stroke-linejoin="round" stroke-width="1"/><path d="M
135.10692 119.41541 C 165.84715 119.854806 204.35783 118.583695 242.39084
112.46344 C 276.08222 107.04184 303.03701 98.838735 323.23284 90.96218"
marker-end="url(#FilledArrow_Marker)" stroke="black" stroke-linecap="round"
stroke-linejoin="round" stroke-width="1"/><path d="M 324.78586 66.603523 C
301.6689 66.933135 270.15767 68.9068 232.17855 75.018384 C 200.11208 80.178506
169.19774 87.361075 143.238715 94.26646" marker-end="url(#FilledArrow_Marker)"
stroke="black" stroke-linecap="round" stroke-linejoin="round"
stroke-width="1"/><rect x="707.0446" y="118.27877" width="85.263146"
height="36.026683" stroke="red" stroke-linecap="round" stroke-linejoin="round"
stroke-width="2"/><text transform="translate(712.0446 127.06811)"
fill="black"><tspan font-family="Helvetica Neue" font-size="16"
font-weight="500" x="7.255573" y="15" textLength="13.92">ar</tspan><tspan
font-family="Helvetica Neue" font-size="16" font-weight="500" x="20.887573"
y="15" textLength="47.12">chived</tspan></text><line x1="682.1782"
y1="136.29211" x2="696.1446" y2="136.29211"
marker-end="url(#FilledArrow_Marker)" stroke="black" stroke-linecap="round"
stroke-linejoin="round" stroke-width="1"/></g></g></svg>
<?xml version="1.0" encoding="UTF-8"?>
<svg width="510.24pt" height="184.25pt" version="1.1" viewBox="0 0 510.24 184.25" xmlns="http://www.w3.org/2000/svg">
<style>
text {
fill: white;
font-family: "Helvetica Neue";
}
</style>
<defs>
<marker id="a" color="black" overflow="visible" markerHeight="6" markerWidth="7" orient="auto" viewBox="-1 -3 7 6">
<path d="m4.8 0-4.8-1.8v3.6z" fill="currentColor" stroke="currentColor"/>
</marker>
</defs>
<g fill="none">
<title>Canvas 1</title>
<rect width="510.24" height="184.25" fill="#fff"/>
<g>
<title>Layer 1</title>
<rect x="5.6693" y="5.6693" width="116.22" height="48.189" fill="#fd8008"/>
<text transform="translate(63.7793 29.7638)" dominant-baseline="middle" text-anchor="middle">experimental</text>
<rect x="161.57" y="113.39" width="150.24" height="68.031" fill="#108001"/>
<text transform="translate(236.69 147.4055)" dominant-baseline="middle" text-anchor="middle" font-size="19">stable</text>
<path d="m63.356 53.858c2.0388 19.203 10.427 45.968 38.691 65.197 13.679 9.3061 30.217 15.625 46.951 19.9" marker-end="url(#a)" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>
<path d="m311.81 131.57c18.392-5.7638 38.128-13.509 56.693-23.85 25.216-14.046 43.275-30.1 55.731-43.973" marker-end="url(#a)" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>
<rect x="391.18" y="119.06" width="113.39" height="48.189" fill="#074080"/>
<text transform="translate(447.875 143.1545)" dominant-baseline="middle" text-anchor="middle">superseded</text>
<line x1="311.81" x2="378.29" y1="147.22" y2="145.23" marker-end="url(#a)" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>
<rect x="391.18" y="5.6693" width="113.39" height="48.189" fill="#fd8008"/>
<text transform="translate(447.875 29.7638)" dominant-baseline="middle" text-anchor="middle">deprecated</text>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -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.

View File

@ -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()}}
}

View File

@ -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")
}
}

View File

@ -28,7 +28,7 @@ random_rsi(size, prob_RSI = c(0.33, 0.33, 0.33), ...)
class \verb{<mic>} for \code{\link[=random_mic]{random_mic()}} (see \code{\link[=as.mic]{as.mic()}}) and class \verb{<disk>} 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.