plot method for objects of class popTime and popTimeExposure
Create a data frame for population time plots to give a visual representation of incidence density
# S3 method for popTime
plot(x, ..., xlab = "Follow-up time", ylab = "Population",
line.width = 1, line.colour = "grey80", point.size = 1,
point.colour = "red", legend = FALSE, legend.position = c("bottom",
"top", "left", "right"))# S3 method for popTimeExposure
plot(x, ..., ncol = 1, xlab = "Follow-up time",
ylab = "Population", line.width = 1, line.colour = "grey80",
point.size = 1, point.colour = "red", legend = FALSE,
legend.position = c("bottom", "top", "left", "right"))
popTime(data, time, event, censored.indicator, exposure)
checkArgsTimeEvent(data, time, event)
an object of class popTime or popTimeExposure.
Ignored.
See
par.
Number of columns.
a data.frame or data.table containing the source
dataset.
a character string giving the name of the time variable. See Details.
a character string giving the name of the event variable
contained in data. See Details. If event is a numeric
variable, then 0 needs to represent a censored observation, 1 needs to be
the event of interest. Integers 2, 3, ... and so on are treated as
competing events. If event is a factor or character and
censored.indicator is not specified, this function will assume the
reference level is the censored indicator
a character string of length 1 indicating which
value in event is the censored. This function will use
relevel to set censored.indicator as the
reference level. This argument is ignored if the event variable is a
numeric
a character string of length 1 giving the name of the
exposure variable which must be contained in data. Default is
NULL. This is used to produced exposure stratified plots. If an
exposure is specified, popTime returns an object of class
popTimeExposure
The methods for plot return a population time plot, stratified by exposure status
in the case of popTimeExposure.
The methods for plot return a population time plot, stratified by exposure status
in the case of popTimeExposure.
An object of class popTime (or popTimeExposure if
exposure is specified), data.table and data.frame in this
order! The output of this function is to be used with the plot method for
objects of class popTime or of class popTimeExposure, which
will produce population time plots
It is assumed that data contains the two columns
corresponding to the supplied time and event variables. If either the
time or event argument is missing, the function looks for
columns that contain the words "time", "event", or
"status" in them (case insensitive). The function first looks for
the time variable, then it looks for the event variable. This order of
operation is important if for example the time variable is named
"event time" and the event variable is named "event
indicator". This function will first (automatically) find the time
variable and remove this as a possibility from subsequent searches of the
event variable.
The following regular expressions are used for the time and event
variables:
"[\s\W_]+time|^time\b"
"[\s\W_]+event|^event\b|[\s\W_]+status|^status\b"
This allows for "time" to be preceded or followed by one or more
white space characters, one or more non-word characters or one or more
underscores. For example, the following column names would be recognized by
the function as the "time" variable: "time of death",
"death_time", "Time", "time", "diagnosis_time", "time.diag", "diag__time".
But the following will not be recognized: "diagtime","eventtime",
"Timediag"
# NOT RUN {
data(bmtccr)
popTimeData <- popTime(data = bmtccr, time = "ftime", exposure = "D")
# p is an object of class gg and ggplot
p <- plot(popTimeData)
# you can further modify the object using all ggplot2 functions
# here we modify the number of y-tick labels
p + scale_y_continuous(breaks = seq(0, max(popTimeData$data$ycoord), 10))
# }
Run the code above in your browser using DataLab