Description Usage Arguments Value Examples
View source: R/plot_top_loadings.R
A plot of the n
largest component loadings is produced.
1 2 3 4 5 6 7 | plot_top_loadings(x, ...)
## S3 method for class 'recipe'
plot_top_loadings(x, ..., n = 4, id = NULL, type = "pca")
## S3 method for class 'workflow'
plot_top_loadings(x, ..., n = 4, id = NULL, type = "pca")
|
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. |
n |
The number of columns to plot (per component). |
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 | library(recipes)
library(parsnip)
library(workflows)
library(ggplot2)
data("cells", package = "modeldata")
theme_set(theme_minimal())
## -----------------------------------------------------------------------------
cell_pca <-
recipe(class ~ ., data = cells %>% dplyr::select(-case)) %>%
step_center(all_predictors()) %>%
step_scale(all_predictors()) %>%
step_pca(all_predictors())
# or when used in a workflow
lr_workflow <-
workflow() %>%
add_model(logistic_reg() %>% set_engine("glm")) %>%
add_recipe(cell_pca)
## -----------------------------------------------------------------------------
cell_pca <- prep(cell_pca)
# What were the top 10 channel 1 columns in the first two components?
plot_top_loadings(cell_pca, grepl("ch_1", terms) & component_number <= 2, n = 10)
## -----------------------------------------------------------------------------
lr_workflow <- lr_workflow %>% fit(data = cells)
plot_top_loadings(lr_workflow, component_number <= 4)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.