1plot.clos.etm <- function(x, xlab = "Time", 2 ylab.e = "Expected LOS", ylab.w = "Weights", 3 xlim, ylim.e, ylim.w, col.e = c(1, 2), col.w = 1, 4 lty.e = c(1, 1), lty.w = 1, legend = TRUE, 5 legend.pos, curvlab, legend.bty = "n", ...) { 6 if (!inherits(x, "clos.etm")) { 7 stop("'x' must be a 'clos.etm' object") 8 } 9 if (missing(xlim)) { 10 xlim <- c(0, max(x$w.time)) 11 } 12 if (missing(ylim.e)) { 13 ylim.e <- c(0, max(c(x$phi.case, x$phi.control))) 14 } 15 if (missing(ylim.w)) { 16 ylim.w <- c(0, max(x$weights)) 17 } 18 def.par <- graphics::par(no.readonly = TRUE) 19 on.exit(par(def.par)) 20 graphics::split.screen(figs=matrix(c(rep(0,2), rep(1,2), c(0, 0.6), c(0.7, 1)), ncol=4)) 21 screen(2) 22 op <- graphics::par(mar=c(2, 5, 2, 1)) 23 graphics::plot(c(0,x$w.time), c(0, x$weights), type = "s", axes = FALSE, lty = lty.w, xlim = xlim, 24 ylim = ylim.w , xlab = xlab , ylab = ylab.w, col=col.w, ...) 25 graphics::axis(side=2) 26 graphics::box() 27 graphics::par(op) 28 graphics::screen(1) 29 op <- graphics::par(mar=c(5, 5, 4, 1)) 30 graphics::plot(x$time, x$phi.case, type = "s", lty = lty.e[1], xlim = xlim, 31 ylim = ylim.e, xlab = xlab, ylab = ylab.e, col = col.e[1], ...) 32 graphics::lines(x$time, x$phi.control, type = "s", lty = lty.e[2], col = col.e[2], ...) 33 graphics::par(op) 34 if (legend == TRUE) { 35 if (missing(legend.pos)) 36 legend.pos <- "bottomright" 37 if (missing(curvlab)) 38 curvlab <- c("Intermediate event by time t", "No intermediate event by time t") 39 if (is.list(legend.pos)) legend.pos <- unlist(legend.pos) 40 if (length(legend.pos) == 1) { 41 xx <- legend.pos 42 yy <- NULL 43 } 44 if (length(legend.pos) == 2) { 45 xx <- legend.pos[1] 46 yy <- legend.pos[2] 47 } 48 args <- list(...) 49 ii <- pmatch(names(args), 50 names(formals("legend")[-charmatch("bty",names(formals("legend")))])) 51 do.call("legend", c(list(xx, yy, curvlab, col = col.e, lty = lty.e, bty = legend.bty), 52 args[!is.na(ii)])) 53 } 54 graphics::close.screen(all.screens = TRUE) 55 invisible() 56} 57