I would like to make a loop to plot data from multiple dataframes in R, using a a pre-existing ggplot function called myplot.
My ggplot function is defined as myplot and the only things I'd like to extract are titles. I know there are similar posts, but none provides a solution for a pre-existing ggplot function.
df1 <- diamonds[1:30,]
df2 <- diamonds[31:60,]
df3 <- diamonds[61:90,]
myplot <- ggplot(df1, aes(x = x, y = y)) +
geom_point(color="grey") +
labs(title = "TITLE")
list <- c("df1","df2","df3")
titles <- c("df1","df2","df3")
Here is my try:
for (i in list) {
myplot(plot_list[[i]])
print(plot_list[[i]])
}