I found this question and tried to apply it to my own situation, but I'm still pretty new to R. I'm trying to take a subset of columns from a dataframe, plot them against every other column from that subset across the time column, then save those plots.
library(dplyr)
library(ggplot2)
library(ggpubr)
auto_graph <-function(.data, x, y){
myplot <- ggplot(.data,
mapping = aes(x = .data[[x]], y = .data[[y]])) +
geom_point(color = "cornflowerblue",
alpha = .5,
size = 3) +
geom_smooth(method = "lm") +
stat_regline_equation(label.y = 25, aes(label = ..eq.label..)) +
stat_regline_equation(label.y = 20, aes(label = ..rr.label..)) +
facet_wrap(~time)
myplot <- myplot + labs(title = paste(names(x), names(y)))
#ggsave(filename=paste(names(x), names(y),".png"), myplot, path="C:/Users/...")
return myplot
}
foo <- lapply(temp, function(x) auto_graph(x, across(3:9), across(3:9)))
foo[[1]]
Now the across didn't work due to lapply not being a dlpr function, but I left it there to give an idea of what I'm trying to do. I did also try using a for-loop first, but whatever way I assigned the x and y in the loop, they ended up as "tbl_df/tbl/data.frame" objects and the plots came up empty.