plot.predict.icfit {icpack} | R Documentation |
Plot method for an object of class 'predict.icfit'
Description
Plot method for an object of class 'predict.icfit'
Usage
## S3 method for class 'predict.icfit'
plot(
x,
type = c("hazard", "cumhazard", "survival", "probability"),
conf.int = TRUE,
fill = TRUE,
fillcol = "lightgrey",
ylim = NULL,
title = NULL,
xlab = NULL,
ylab = NULL,
selection = NULL,
nrow = NULL,
ncol = NULL,
do_plot = TRUE,
...
)
Arguments
x |
The object of class 'predict.icfit' to be plotted |
type |
Type of plot. Accepted choices: 'hazard' (default), 'cumhazard', 'survival' or 'probability' |
conf.int |
If 'TRUE' a 100*(1 - alpha) percent confidence interval is plotted |
fill |
Fill area between lower and upper |
fillcol |
The color for filling (default 'lightgrey') |
ylim |
The y-limits for the plot |
title |
Optional title string, or, if x is a list, obtained from 'predict.icfit' using 'newdata', a vector of title strings |
xlab |
Text for x-label |
ylab |
Text for y-label |
selection |
If x is a list, obtained from 'predict.icfit' using 'newdata', then a vector containing the subset of list elements to be plotted, default is to plot all elements of the list |
nrow |
If x is a list, obtained from 'predict.icfit' using 'newdata', then a number specifying the number of rows to plot; default the square root of the number of list elements to be plotted |
ncol |
If x is a list, obtained from 'predict.icfit' using 'newdata', then a number specifying the number of columns to plot; default the square root of the number of list elements to be plotted |
do_plot |
Boolean indicating whether or not to actually plot (default is TRUE) |
... |
other graphical parameters to be passed on |
Value
A ggplot grob, containing the plot. Use print()
or plot()
to show it
Multiple objects can be combined by using functions in the package gridExtra
.
Examples
icf <- icfit(Surv(left, right, type='interval2') ~ period + gender + age, data=drugusers)
pred_icf <- predict(icf)
plot(pred_icf)
library(ggplot2)
plot(icf) + xlim(0, 200) + ylim(0, 0.05)
ndata <- drugusers[1:4, ]
pred_nd_icf <- predict(icf, newdata=ndata)
plot(pred_nd_icf) # plot all four
plot(pred_nd_icf[[2]]) # plot only the second
plot(pred_nd_icf, type = "cumhazard") # plot four cumulative hazard curves
plot(pred_nd_icf[[3]], type = "prob", ylim = c(0, 1)) # plot probability curve for nr 3
plot(pred_nd_icf[[4]], type = "surv", ylim = c(0, 1)) # plot survival curve for nr 4