Description Usage Arguments Value Examples
View source: R/plot_loadings.R
A plot of the component loadings for each original column of the data is produced.
1 2 3 4 5 6 7 | plot_loadings(x, ...)
## S3 method for class 'recipe'
plot_loadings(x, ..., id = NULL, type = "pca")
## S3 method for class 'workflow'
plot_loadings(x, ..., id = NULL)
|
x |
A prepped recipe or fitted workflow that uses a recipe. The recipe
must have used at least one |
... |
An optional series of conditional statements used to filter the PCA data before plotting. See Details below. |
id |
A single numeric or character value that is used to pick the step
with the PCA results. If a single |
type |
A character value ("pca" or "pls") for the type of step to use. |
A ggplot
object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | library(recipes)
library(parsnip)
library(workflows)
library(ggplot2)
data("Chicago", package = "modeldata")
theme_set(theme_minimal())
## -----------------------------------------------------------------------------
train_pca <-
recipe(ridership ~ ., data = Chicago %>% dplyr::select(1:21)) %>%
step_center(all_predictors()) %>%
step_scale(all_predictors()) %>%
step_pca(all_predictors())
# or when used in a workflow
lm_workflow <-
workflow() %>%
add_model(linear_reg() %>% set_engine("lm")) %>%
add_recipe(train_pca)
## -----------------------------------------------------------------------------
train_pca <- prep(train_pca)
plot_loadings(train_pca, component_number <= 3)
plot_loadings(train_pca, component_number <= 3, value > 0)
## -----------------------------------------------------------------------------
lm_workflow <- lm_workflow %>% fit(data = Chicago)
plot_loadings(lm_workflow, component_number <= 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.