The following code is a minimal example of what I have and what I am trying to achieve. The idea is I have a large chunk of code that builds up a plot in many steps. I want to save the plot as a png at different steps along the way.
This chunk works...
x<-runif(10)
y<-runif(10)
png(filename="Plot0.png")
plot(y~x)
abline(h=mean(y))
dev.off()
but when I split the plot chunks yet want to save each step individually there's a problem.
x<-runif(10)
y<-runif(10)
png(filename="Plot1.png")
plot(y~x)
dev.off()
png(filename="Plot2.png")
abline(h=mean(y))
dev.off()
The problem is plot.new has not been called yet
. This I have searched but I can't seem to find the bits that make it work.