Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206235

In r, how to save plot and reuse the plot code

$
0
0

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.


Viewing all articles
Browse latest Browse all 206235

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>