https://github.com/cran/cutpointr
Tip revision: 7e56c827a694247d212e9a0167a119f917e1f31b authored by Christian Thiele on 31 August 2018, 15:50:10 UTC
version 0.7.4
version 0.7.4
Tip revision: 7e56c82
plot.cutpointr.R
#' Plot cutpointr objects
#'
#' The plot layout depends on whether subgroups were defined and whether
#' bootstrapping was run.
#'
#' The \code{...} argument can be used to apply \pkg{ggplot2} functions to every individual
#' plot, for example for changing the theme.
#'
#' @param x A cutpointr object.
#' @param ... Further arguments.
#' @examples
#' opt_cut <- cutpointr(suicide, dsi, suicide, gender)
#' plot(opt_cut)
#' plot(opt_cut, ggplot2::theme_bw())
#' @family cutpointr plotting functions
#' @export
plot.cutpointr <- function(x, ...) {
args <- list(...)
dist <- plot_x(x)
roc <- plot_roc(x)
boot_flag <- has_boot_results(x)
if (boot_flag) {
boot_cut <- plot_cut_boot(x)
boot_metric <- plot_metric_boot(x)
} else {
boot_cut <- NULL
boot_metric <- NULL
}
#
# Compose plots
#
plots <- list(dist, roc, boot_cut, boot_metric)
keep <- !(purrr::map_lgl(plots, is.null))
plots <- plots[keep]
plots <- lapply(plots, function(p) p + args)
rows <- round(sum(keep) / 2)
pos <- ifelse(rows > 1, "right", "bottom")
suppressMessages(p <- grid_arrange_shared_legend(plots,
nrow = rows, ncol = 2,
position = pos))
invisible(p)
}