knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(recipes) library(tidymodels.ext) library(ggplot2)
df <- tibble::tibble( x = seq(1,100,by=1), y = rep(c(0,1),50), z = seq(0.01,1,by=0.01)^2 + 3) rec_obj <- df |> recipe(y ~ .) |> step_top_code_quant(all_numeric_predictors(),prob = 0.9) rec_obj_prepped <- prep(rec_obj, training = df)
bind_cols( df %>% rename_with(~ paste0(.x,"_original")), bake(rec_obj_prepped, df) |> rename_with(~ paste0(.x,"_transformed"))) |> tibble::rownames_to_column() |> tidyr::pivot_longer(-rowname) |> tidyr::separate(name,into = c("variable","type"), sep="_") |> tidyr::pivot_wider( id_cols = c("rowname","variable"), names_from = "type") |> ggplot() + geom_point(aes(x=original,y=transformed)) + facet_wrap(vars(variable), nrow=1, scales = "free")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.