if (FALSE) { # rlang::is_installed(c("patchwork", "glmnet", "ggrepel"))
library(dplyr)
library(tidyr)
library(purrr)
library(parsnip)
library(glmnet)
library(ggplot2)
data <- filter(example_nested_data, id %in% 16:20)
nested_data <- nest(data, data = -id2)
model <- linear_reg(penalty = 1) %>%
set_engine("glmnet") %>%
nested()
fit <- fit(model, z ~ x + y + a + b, nested_data)
plots <- autoplot(fit)
# View the first plot
plots[[1]]
# Use the patchwork package (or others) to combine the plots
library(patchwork)
reduce(plots, `+`)
}
Run the code above in your browser using DataLab