I would like to use a parent function that creates two additional plot functions, and when I call the parent function, I would like both plots to be returned. Ideally, I would like the plots to be returned as two separate objects instead of using something like par() to combine the two plots into a single image.
The code below only returns the second of the two plots.
test_fx <- function() {
# Define the first plot
plot1_fx <- function() {
plot(x=c(1,2,3),y=c(3,4,5), type='l')
abline(v=1.5, col="red", lwd=5)
}
# Define the second plot
plot2_fx <- function() {
plot(x=c(1,2,3),y=c(5,4,3), type='l')
abline(v=2.5, col="blue", lwd=5)
}
# Return the plots
plot1_fx()
plot2_fx()
}
# Call the main function
test_fx()


windows.options(record = TRUE)will save each plot in the historial.