% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot.gg_variable.R
\name{plot.gg_variable}
\alias{plot.gg_variable}
\title{Plot a \code{\link{gg_variable}} object,}
\usage{
\method{plot}{gg_variable}(
  x,
  xvar,
  time,
  time_labels,
  panel = FALSE,
  oob = TRUE,
  points = TRUE,
  smooth = TRUE,
  ...
)
}
\arguments{
\item{x}{\code{\link{gg_variable}} object created from a
\code{\link[randomForestSRC]{rfsrc}} object}

\item{xvar}{variable (or list of variables) of interest.}

\item{time}{For survival, one or more times of interest}

\item{time_labels}{string labels for times}

\item{panel}{Should plots be faceted along multiple xvar?}

\item{oob}{oob estimates (boolean)}

\item{points}{plot the raw data points (boolean)}

\item{smooth}{include a smooth curve (boolean)}

\item{...}{arguments passed to the \code{ggplot2} functions.}
}
\value{
A single \code{ggplot} object when \code{length(xvar) == 1} or
  \code{panel = TRUE}. Otherwise a named list of \code{ggplot} objects, one
  per variable in \code{xvar}.
}
\description{
Plot a \code{\link{gg_variable}} object,
}
\examples{
## ------------------------------------------------------------
## classification
## ------------------------------------------------------------
## -------- iris data
set.seed(42)
rfsrc_iris <- rfsrc(Species ~ ., data = iris, ntree = 50)

gg_dta <- gg_variable(rfsrc_iris)
plot(gg_dta, xvar = "Sepal.Width")
plot(gg_dta, xvar = "Sepal.Length")

## Panel plot across all predictors
plot(gg_dta,
  xvar = rfsrc_iris$xvar.names,
  panel = TRUE, se = FALSE
)

## ------------------------------------------------------------
## regression
## ------------------------------------------------------------
## -------- air quality data
# na.action = "na.impute" handles missing Ozone / Solar.R values
set.seed(42)
rfsrc_airq <- rfsrc(Ozone ~ ., data = airquality,
                    na.action = "na.impute", ntree = 50)
gg_dta <- gg_variable(rfsrc_airq)

# Treat Month as an ordinal factor for better visualisation
gg_dta[, "Month"] <- factor(gg_dta[, "Month"])

plot(gg_dta, xvar = "Wind")
plot(gg_dta, xvar = "Temp")
plot(gg_dta, xvar = "Solar.R")

# Panel plot across continuous predictors
plot(gg_dta, xvar = c("Solar.R", "Wind", "Temp", "Day"), panel = TRUE)

# Factor variable uses notched boxplots
plot(gg_dta, xvar = "Month", notch = TRUE)

## ------------------------------------------------------------
## survival examples
## ------------------------------------------------------------
## -------- veteran data
data(veteran, package = "randomForestSRC")
set.seed(42)
rfsrc_veteran <- rfsrc(Surv(time, status) ~ ., veteran,
  nsplit = 10,
  ntree = 50
)

# Marginal survival at 90 days
gg_dta <- gg_variable(rfsrc_veteran, time = 90)

# Single-variable dependence plots
plot(gg_dta, xvar = "age")
plot(gg_dta, xvar = "diagtime")

# Panel coplot for two predictors at a single time
plot(gg_dta, xvar = c("age", "diagtime"), panel = TRUE)

# Compare survival at 30, 90, and 365 days simultaneously
gg_dta <- gg_variable(rfsrc_veteran, time = c(30, 90, 365))

# Single-variable plot (one facet per time point)
plot(gg_dta, xvar = "age")

# Panel coplot across two predictors and three time points
plot(gg_dta, xvar = c("age", "diagtime"), panel = TRUE)

}
\references{
Breiman L. (2001). Random forests, Machine Learning, 45:5-32.

Ishwaran H. and Kogalur U.B. (2007). Random survival forests for R, Rnews,
7(2):25-31.

Ishwaran H. and Kogalur U.B. randomForestSRC: Random Forests for Survival,
Regression and Classification. R package version >= 3.4.0.
\url{https://cran.r-project.org/package=randomForestSRC}
}
\seealso{
\code{\link{gg_variable}}, \code{\link{gg_partial}},
  \code{\link[randomForestSRC]{plot.variable}}
}
