Learn R Programming

caret (version 6.0-80)

ggplot.train: Plot Method for the train Class

Description

This function takes the output of a train object and creates a line or level plot using the lattice or ggplot2 libraries.

Usage

# S3 method for train
ggplot(data = NULL, mapping = NULL,
  metric = data$metric[1], plotType = "scatter", output = "layered",
  nameInStrip = FALSE, highlight = FALSE, ..., environment = NULL)

# S3 method for train plot(x, plotType = "scatter", metric = x$metric[1], digits = getOption("digits") - 3, xTrans = NULL, nameInStrip = FALSE, ...)

Arguments

data

an object of class train.

mapping, environment

unused arguments to make consistent with ggplot2 generic method

metric

What measure of performance to plot. Examples of possible values are "RMSE", "Rsquared", "Accuracy" or "Kappa". Other values can be used depending on what metrics have been calculated.

plotType

a string describing the type of plot ("scatter", "level" or "line" (plot only))

output

either "data", "ggplot" or "layered". The first returns a data frame while the second returns a simple ggplot object with no layers. The third value returns a plot with a set of layers.

nameInStrip

a logical: if there are more than 2 tuning parameters, should the name and value be included in the panel title?

highlight

a logical: if TRUE, a diamond is placed around the optimal parameter setting for models using grid search.

plot only: specifications to be passed to levelplot, xyplot, stripplot (for line plots). The function automatically sets some arguments (e.g. axis labels) but passing in values here will over-ride the defaults

x

an object of class train.

digits

an integer specifying the number of significant digits used to label the parameter value.

xTrans

a function that will be used to scale the x-axis in scatter plots.

Details

If there are no tuning parameters, or none were varied, an error is produced.

If the model has one tuning parameter with multiple candidate values, a plot is produced showing the profile of the results over the parameter. Also, a plot can be produced if there are multiple tuning parameters but only one is varied.

If there are two tuning parameters with different values, a plot can be produced where a different line is shown for each value of of the other parameter. For three parameters, the same line plot is created within conditioning panels/facets of the other parameter.

Also, with two tuning parameters (with different values), a levelplot (i.e. un-clustered heatmap) can be created. For more than two parameters, this plot is created inside conditioning panels/facets.

References

Kuhn (2008), ``Building Predictive Models in R Using the caret'' (http://www.jstatsoft.org/article/view/v028i05/v28i05.pdf)

See Also

train, levelplot, xyplot, stripplot, ggplot

Examples

Run this code
# NOT RUN {

# }
# NOT RUN {
library(klaR)
rdaFit <- train(Species ~ .,
                data = iris, 
                method = "rda", 
                control = trainControl(method = "cv"))
plot(rdaFit)
plot(rdaFit, plotType = "level")

ggplot(rdaFit) + theme_bw()

# }
# NOT RUN {
 
# }

Run the code above in your browser using DataLab