Plots the event data and the estimated CMA per treatment episode and sliding window, respectively.
# S3 method for CMA_per_episode
plot(
x,
patients.to.plot = NULL,
duration = NA,
align.all.patients = FALSE,
align.first.event.at.zero = TRUE,
show.period = c("dates", "days")[2],
period.in.days = 90,
show.legend = TRUE,
legend.x = "right",
legend.y = "bottom",
legend.bkg.opacity = 0.5,
legend.cex = 0.75,
legend.cex.title = 1,
cex = 1,
cex.axis = 0.75,
cex.lab = 1,
show.cma = TRUE,
xlab = c(dates = "Date", days = "Days"),
ylab = c(withoutCMA = "patient", withCMA = "patient (& CMA)"),
title = c(aligned = "Event patterns (all patients aligned)", notaligned =
"Event patterns"),
col.cats = rainbow,
unspecified.category.label = "drug",
medication.groups.to.plot = NULL,
medication.groups.separator.show = TRUE,
medication.groups.separator.lty = "solid",
medication.groups.separator.lwd = 2,
medication.groups.separator.color = "blue",
medication.groups.allother.label = "*",
lty.event = "solid",
lwd.event = 2,
pch.start.event = 15,
pch.end.event = 16,
plot.events.vertically.displaced = TRUE,
print.dose = FALSE,
cex.dose = 0.75,
print.dose.outline.col = "white",
print.dose.centered = FALSE,
plot.dose = FALSE,
lwd.event.max.dose = 8,
plot.dose.lwd.across.medication.classes = FALSE,
col.na = "lightgray",
col.continuation = "black",
lty.continuation = "dotted",
lwd.continuation = 1,
print.CMA = TRUE,
CMA.cex = 0.5,
plot.CMA = TRUE,
plot.CMA.as.histogram = TRUE,
plot.partial.CMAs.as = c("stacked", "overlapping", "timeseries")[1],
plot.partial.CMAs.as.stacked.col.bars = "gray90",
plot.partial.CMAs.as.stacked.col.border = "gray30",
plot.partial.CMAs.as.stacked.col.text = "black",
plot.partial.CMAs.as.timeseries.vspace = 7,
plot.partial.CMAs.as.timeseries.start.from.zero = TRUE,
plot.partial.CMAs.as.timeseries.col.dot = "darkblue",
plot.partial.CMAs.as.timeseries.col.interval = "gray70",
plot.partial.CMAs.as.timeseries.col.text = "firebrick",
plot.partial.CMAs.as.timeseries.interval.type = c("none", "segments", "arrows",
"lines", "rectangles")[2],
plot.partial.CMAs.as.timeseries.lwd.interval = 1,
plot.partial.CMAs.as.timeseries.alpha.interval = 0.25,
plot.partial.CMAs.as.timeseries.show.0perc = TRUE,
plot.partial.CMAs.as.timeseries.show.100perc = FALSE,
plot.partial.CMAs.as.overlapping.alternate = TRUE,
plot.partial.CMAs.as.overlapping.col.interval = "gray70",
plot.partial.CMAs.as.overlapping.col.text = "firebrick",
CMA.plot.ratio = 0.1,
CMA.plot.col = "lightgreen",
CMA.plot.border = "darkgreen",
CMA.plot.bkg = "aquamarine",
CMA.plot.text = CMA.plot.border,
highlight.followup.window = TRUE,
followup.window.col = "green",
highlight.observation.window = TRUE,
observation.window.col = "yellow",
observation.window.opacity = 0.3,
alternating.bands.cols = c("white", "gray95"),
bw.plot = FALSE,
force.draw.text = FALSE,
min.plot.size.in.characters.horiz = 0,
min.plot.size.in.characters.vert = 0,
max.patients.to.plot = 100,
export.formats = NULL,
export.formats.fileprefix = "AdhereR-plot",
export.formats.height = NA,
export.formats.width = NA,
export.formats.save.svg.placeholder = TRUE,
export.formats.svg.placeholder.type = c("jpg", "png", "webp")[2],
export.formats.svg.placeholder.embed = FALSE,
export.formats.html.template = NULL,
export.formats.html.javascript = NULL,
export.formats.html.css = NULL,
export.formats.directory = NA,
generate.R.plot = TRUE,
suppress.warnings = FALSE,
...
)# S3 method for CMA_sliding_window
plot(
x,
patients.to.plot = NULL,
duration = NA,
align.all.patients = FALSE,
align.first.event.at.zero = TRUE,
show.period = c("dates", "days")[2],
period.in.days = 90,
show.legend = TRUE,
legend.x = "right",
legend.y = "bottom",
legend.bkg.opacity = 0.5,
legend.cex = 0.75,
legend.cex.title = 1,
cex = 1,
cex.axis = 0.75,
cex.lab = 1,
show.cma = TRUE,
xlab = c(dates = "Date", days = "Days"),
ylab = c(withoutCMA = "patient", withCMA = "patient (& CMA)"),
title = c(aligned = "Event patterns (all patients aligned)", notaligned =
"Event patterns"),
col.cats = rainbow,
unspecified.category.label = "drug",
medication.groups.to.plot = NULL,
medication.groups.separator.show = TRUE,
medication.groups.separator.lty = "solid",
medication.groups.separator.lwd = 2,
medication.groups.separator.color = "blue",
medication.groups.allother.label = "*",
lty.event = "solid",
lwd.event = 2,
pch.start.event = 15,
pch.end.event = 16,
plot.events.vertically.displaced = TRUE,
print.dose = FALSE,
cex.dose = 0.75,
print.dose.outline.col = "white",
print.dose.centered = FALSE,
plot.dose = FALSE,
lwd.event.max.dose = 8,
plot.dose.lwd.across.medication.classes = FALSE,
col.na = "lightgray",
col.continuation = "black",
lty.continuation = "dotted",
lwd.continuation = 1,
print.CMA = TRUE,
CMA.cex = 0.5,
plot.CMA = TRUE,
plot.CMA.as.histogram = TRUE,
plot.partial.CMAs.as = c("stacked", "overlapping", "timeseries")[1],
plot.partial.CMAs.as.stacked.col.bars = "gray90",
plot.partial.CMAs.as.stacked.col.border = "gray30",
plot.partial.CMAs.as.stacked.col.text = "black",
plot.partial.CMAs.as.timeseries.vspace = 7,
plot.partial.CMAs.as.timeseries.start.from.zero = TRUE,
plot.partial.CMAs.as.timeseries.col.dot = "darkblue",
plot.partial.CMAs.as.timeseries.col.interval = "gray70",
plot.partial.CMAs.as.timeseries.col.text = "firebrick",
plot.partial.CMAs.as.timeseries.interval.type = c("none", "segments", "arrows",
"lines", "rectangles")[2],
plot.partial.CMAs.as.timeseries.lwd.interval = 1,
plot.partial.CMAs.as.timeseries.alpha.interval = 0.25,
plot.partial.CMAs.as.timeseries.show.0perc = TRUE,
plot.partial.CMAs.as.timeseries.show.100perc = FALSE,
plot.partial.CMAs.as.overlapping.alternate = TRUE,
plot.partial.CMAs.as.overlapping.col.interval = "gray70",
plot.partial.CMAs.as.overlapping.col.text = "firebrick",
CMA.plot.ratio = 0.1,
CMA.plot.col = "lightgreen",
CMA.plot.border = "darkgreen",
CMA.plot.bkg = "aquamarine",
CMA.plot.text = CMA.plot.border,
highlight.followup.window = TRUE,
followup.window.col = "green",
highlight.observation.window = TRUE,
observation.window.col = "yellow",
observation.window.opacity = 0.3,
alternating.bands.cols = c("white", "gray95"),
bw.plot = FALSE,
force.draw.text = FALSE,
min.plot.size.in.characters.horiz = 0,
min.plot.size.in.characters.vert = 0,
max.patients.to.plot = 100,
export.formats = NULL,
export.formats.fileprefix = "AdhereR-plot",
export.formats.height = NA,
export.formats.width = NA,
export.formats.save.svg.placeholder = TRUE,
export.formats.svg.placeholder.type = c("jpg", "png", "webp")[2],
export.formats.svg.placeholder.embed = FALSE,
export.formats.html.template = NULL,
export.formats.html.javascript = NULL,
export.formats.html.css = NULL,
export.formats.directory = NA,
generate.R.plot = TRUE,
suppress.warnings = FALSE,
...
)
A CMA0
or derived object, representing the CMA to
plot
A vector of strings containing the list of
patient IDs to plot (a subset of those in the cma
object), or
NULL
for all
A number, the total duration (in days) of the whole
period to plot; in NA
it is automatically determined from the event
data such that the whole dataset fits.
Logical, should all patients be aligned (i.e., the actual dates are discarded and all plots are relative to the earliest date)?
Logical, should the first event be placed at the origin of the time axis (at 0)?
A string, if "dates" show the actual dates at the
regular grid intervals, while for "days" (the default) shows the days since
the beginning; if align.all.patients == TRUE
, show.period
is
taken as "days".
The number of days at which the regular grid is drawn (or 0 for no grid).
Logical, should the legend be drawn?
The position of the legend on the x axis; can be "left", "right" (default), or a numeric value.
The position of the legend on the y axis; can be "bottom" (default), "top", or a numeric value.
A number between 0.0 and 1.0 specifying the opacity of the legend background.
The legend and legend title font sizes.
numeric values specifying the cex of the various types of text.
Logical, should the CMA type be shown in the title?
Named vector of x-axis labels to show for the two types of periods
("days" and "dates"), or a single value for both, or NULL
for nothing.
Named vector of y-axis labels to show without and with CMA estimates,
or a single value for both, or NULL
for nonthing.
Named vector of titles to show for and without alignment, or a
single value for both, or NULL
for nonthing.
A color or a function that specifies the single
colour or the colour palette used to plot the different medication; by
default rainbow
, but we recommend, whenever possible, a
colorblind-friendly palette such as viridis
or colorblind_pal
.
A string giving the name of the unspecified (generic) medication category.
the names of the medication groups to plot or
NULL
(the default) for all.
a boolean, if TRUE
(the
default) visually mark the medication groups the belong to the same patient,
using horizontal lines and alternating vertical lines.
graphical parameters (line type, line width and colour describing the visual marking og medication groups as beloning to the same patient.
a string giving the label to
use for the implicit __ALL_OTHERS__
medication group (defaults to "*").
The style of the event (line style, width, and start and end symbols).
Should consecutive events be plotted on separate rows (i.e., separated vertically, the default) or on the same row?
Print daily dose as a number and, if so, how (color, size, position...).
Show dose through the width of the event lines and, if so, what the maximum width should be, and should this maximum be by medication class or overall.
The colour used for missing event data.
The color, style and width of the contuniation lines connecting consecutive events.
Logical, should the CMA values be printed?
... and, if printed, what cex (numeric) to use?
Logical, should the distribution of the CMA values
across episodes/sliding windows be plotted? If TRUE
(the default), the
distribution is shown on the left-hand side of the plot, otherwise it is not.
Logical, should the CMA plot be a histogram or a (truncated) density plot? Please note that it is TRUE by deafult for CMA_per_episode and FALSE for CMA_sliding_window, because usually there are more sliding windows than episodes. Also, the density estimate cannot be estimated for less than three different values.
Should the partial CMAs be plotted? Possible values
are "stacked", "overlapping" or "timeseries", or NULL
for no partial
CMA plots. Please note that plot.CMA
and plot.partial.CMAs.as
are independent of each other.
If plotting the partial CMAs as stacked bars, define their graphical attributes.
If plotting the partial CMAs as imeseries, these are their graphical attributes.
If plotting the partial CMAs as overlapping segments, these are their graphical attributes.
A number, the proportion of the total horizontal plot space to be allocated to the CMA plot.
Strings giving the colours of the various components of the CMA plot.
Logical, should the follow-up window be plotted?
The follow-up window colour.
Logical, should the observation window be plotted?
Attributes of the observation window (colour, transparency).
The colors of the alternating vertical bands
distinguishing the patients; can be NULL
= don't draw the bandes;
or a vector of colors.
Logical, should the plot use grayscale only (i.e., the
gray.colors
function)?
Logical, if TRUE
, always draw text even
if too big or too small
Numeric, the minimum size of the plotting surface in characters;
horizontally (min.plot.size.in.characters.horiz) refers to the the whole
duration of the events to plot; vertically (min.plot.size.in.characters.vert)
refers to a single event. If the plotting is too small, possible solutions
might be: if within RStudio
, try to enlarge the "Plots" panel, or
(also valid outside RStudio
but not if using RStudio server
start a new plotting device (e.g., using X11()
, quartz()
or windows()
, depending on OS) or (works always) save to an image
(e.g., jpeg(...); ...; dev.off()
) and display it in a viewer.
Numeric, the maximum patients to attempt to plot.
a string giving the formats to export the figure
to (by default NULL
, meaning no exporting); can be any combination of
"svg" (just an SVG
file), "html" (SVG
+ HTML
+ CSS
+ JavaScript
, all embedded within one HTML
document), "jpg",
"png", "webp", "ps" or "pdf".
a string giving the file name prefix for the exported formats (defaults to "AdhereR-plot").
numbers giving the
desired dimensions (in pixels) for the exported figure (defaults to sane
values if NA
).
a logical, if TRUE, save an
image placeholder of type given by export.formats.svg.placeholder.type
for the SVG
image.
a string, giving the type of
placeholder for the SVG
image to save; can be "jpg",
"png" (the default) or "webp".
a logical, if TRUE
,
embed the placeholder image in the HTML document (if any) using base64
encoding, otherwise (the default) leave it as an external image file (works
only when an HTML
document is exported and only for JPEG
or
PNG
images.
character strings or NULL
(the default) giving the path to the
HTML
, JavaScript
and CSS
templates, respectively, to be
used when generating the HTML+CSS semi-interactive plots; when NULL
,
the default ones included with the package will be used. If you decide to define
new templates please use the default ones for inspiration and note that future
version are not guaranteed to be backwards compatible!
a string; if exporting, which directory
to export to; if NA
(the default), creates the files in a temporary
directory.
a logical, if TRUE
(the default),
generate the standard (base R
) plot for plotting within R
.
Logical, if TRUE
don't show any
warnings.
other parameters (to be passed to the estimation and plotting of the simple CMA)
The x-axis represents time (either in days since the earliest date or as actual dates), with consecutive events represented as ascending on the y-axis.
Each event is represented as a segment with style lty.event
and line
width lwd.event
starting with a pch.start.event
and ending with
a pch.end.event
character, coloured with a unique color as given by
col.cats
, extending from its start date until its end date.
Consecutive events are thus represented on consecutive levels of the y-axis
and are connected by a "continuation" line with col.continuation
colour, lty.continuation
style and lwd.continuation
width;
these continuation lines are purely visual guides helping to perceive the
sequence of events, and carry no information about the avilability of
medicine in this interval.
Above these, the treatment episodes or the sliding windows are represented in a stacked manner from the earlieast (left, bottom of the stack) to the latest (right, top of the stack), each showing the CMA as percent fill (capped at 100% even if CMA values may be higher) and also as text.
The follow-up and the observation windows are plotted as empty an rectangle and as shaded rectangle, respectively (for some CMAs the observation window might be adjusted in which case the adjustment may also be plotted using a different shading).
The kernel density ("smoothed histogram") of the CMA estimates across treatment episodes/sliding windows (if more than 2) can be visually represented as well in the left side of the figure (NB, their horizontal scales may be different across patients).
When several patients are displayed on the same plot, they are organized
vertically, and alternating bands (white and gray) help distinguish
consecutive patients.
Implicitely, all patients contained in the cma
object will be plotted,
but the patients.to.plot
parameter allows the selection of a subset
of patients.
Finally, the y-axis shows the patient ID and possibly the CMA estimate as well.
Any not explicitely defined arguments are passed to the simple CMA estimation and plotting function; therefore, for more info about possible estimation parameters plese see the help for the appropriate simple CMA, and for possible aesthetic tweaks, please see the help for their plotting.
See the simple CMA estimation CMA1
to CMA9
and plotting plot.CMA1
functions for extra parameters.
# NOT RUN {
cmaW <- CMA_sliding_window(CMA=CMA1,
data=med.events,
ID.colname="PATIENT_ID",
event.date.colname="DATE",
event.duration.colname="DURATION",
event.daily.dose.colname="PERDAY",
medication.class.colname="CATEGORY",
carry.only.for.same.medication=FALSE,
consider.dosage.change=FALSE,
followup.window.start=0,
observation.window.start=0,
observation.window.duration=365,
sliding.window.start=0,
sliding.window.start.unit="days",
sliding.window.duration=90,
sliding.window.duration.unit="days",
sliding.window.step.duration=7,
sliding.window.step.unit="days",
sliding.window.no.steps=NA,
date.format="%m/%d/%Y"
);
plot(cmaW, patients.to.plot=c("1","2"));
cmaE <- CMA_per_episode(CMA=CMA1,
data=med.events,
ID.colname="PATIENT_ID",
event.date.colname="DATE",
event.duration.colname="DURATION",
event.daily.dose.colname="PERDAY",
medication.class.colname="CATEGORY",
carry.only.for.same.medication=FALSE,
consider.dosage.change=FALSE,
followup.window.start=0,
observation.window.start=0,
observation.window.duration=365,
date.format="%m/%d/%Y"
);
plot(cmaE, patients.to.plot=c("1","2"));
# }
Run the code above in your browser using DataLab