I am making a function call in R. The function returns a list and in it has a call to plot(). From this one call, I need to record the plot as an object and store the list as a separate object. I need to store the plot because I later give it to ggarrange() along with other plots. I must store both outputs in one call of the function because the function runs permutations. As a result, it will produce a slightly different output each time. Therefore, in order for the data in the list to match the plot, the call can only be made once.
The line of code below is what I am currently using that successfully stores the plot as ggplot object. It does not store the list.
my_plot <- as.ggplot(~(my_function(input1,input2, permutations=1000)))
The code below will return the list, but not save the plot.
my_list <- my_function(input1,input2, permutations=1000)
Does anyone know a way of accomplishing what I am trying to do?