map.event.coords.to.plot: Map from event to plot coordinates.

View source: R/plotting.R

map.event.coords.to.plotR Documentation

Map from event to plot coordinates.

Description

Maps the (x,y) coordinates in the event space to the plotting space.

Usage

map.event.coords.to.plot(
  x = NA,
  y = NA,
  x.is.Date = FALSE,
  x.date.format = "%m/%d/%Y",
  adjust.for.earliest.date = TRUE,
  plot.type = c("baseR", "SVG")[1],
  suppress.warnings = FALSE
)

Arguments

x

The x coordinate in the event space, either a number giving the number of days since the earliest plotted date, or a Date or a string in the format given by the x.date.format parameter giving the actual calendar date.

y

The y coordinate in the event space, thus a number giving the plot row.

x.is.Date

A logical, being TRUE if x is a string giving the date in the x.date.format format.

x.date.format

A string giving the format of the x date, if x.is.Date id TRUE.

adjust.for.earliest.date

A logical which is TRUE if x is a calendar date that must be adjusted for the earliest plotted date (by default TRUE).

plot.type

Can be either "baseR" or "SVG" and specifies to which type of plotting the mapping applies.

suppress.warnings

Logical, if TRUE don't show any warnings.

Details

This is intended for advanced users only. In the event space, the x coordinate can be either given as the number of days since the first plotted event, or as an actual calendar date (either as a Date object or a string with a given format; a date may or may not be corrected relative to the first displayed date). On the y coordinate, the plotting is divided in equally spaced rows, each row corresponding to a single event or an element of a partial CMA plot (one can specify in between rows using fractions). Any or both of x and y can be missing.

Value

A numeric vector with x and y components giving the plotting coordinates, or NULL in case of error.

Examples

cma7 <- CMA7(data=med.events[med.events$PATIENT_ID %in% c(1,2),],
             ID.colname="PATIENT_ID",
             event.date.colname="DATE",
             event.duration.colname="DURATION",
             event.daily.dose.colname="PERDAY",
             medication.class.colname="CATEGORY",
             followup.window.start=0,
             followup.window.start.unit="days",
             followup.window.duration=2*365,
             followup.window.duration.unit="days",
             observation.window.start=30,
             observation.window.start.unit="days",
             observation.window.duration=365,
             observation.window.duration.unit="days",
             date.format="%m/%d/%Y",
             summary="Base CMA");
plot(cma7);
# Add a transparent blue rect:
rect(map.event.coords.to.plot(x=270),
     get.event.plotting.area()["y.min"]-1,
     map.event.coords.to.plot(x="03/15/2037", x.is.Date=TRUE, x.date.format="%m/%d/%Y"),
     get.event.plotting.area()["y.max"]+1,
     col=adjustcolor("blue",alpha.f=0.5), border="blue");

AdhereR documentation built on July 5, 2022, 5:08 p.m.