View source: R/plot.gg_variable.R
| plot.gg_variable | R Documentation |
gg_variable object,Plot a gg_variable object,
## S3 method for class 'gg_variable'
plot(
x,
xvar,
time,
time_labels,
panel = FALSE,
oob = TRUE,
points = TRUE,
smooth = TRUE,
...
)
x |
|
xvar |
variable (or list of variables) of interest. |
time |
For survival, one or more times of interest |
time_labels |
string labels for times |
panel |
Should plots be faceted along multiple xvar? |
oob |
oob estimates (boolean) |
points |
plot the raw data points (boolean) |
smooth |
include a smooth curve (boolean) |
... |
arguments passed to the |
A single ggplot object when length(xvar) == 1 or
panel = TRUE. Otherwise a named list of ggplot objects, one
per variable in xvar.
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. https://cran.r-project.org/package=randomForestSRC
gg_variable, gg_partial,
plot.variable
## ------------------------------------------------------------
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.