0

I want to plot a number of graph using this for loop. however, I can only get one output (foo0001).

for (i in 1:5) {
 bitmap("foo%03d.jpg")
 plot(runif(20), ylim = c(0, 1))
 dev.off()
}

please help!

1 Answer 1

2

bitmap writes each page (plot) to consecutive files according to the format string chosen. Calling bitmap creates a new graphics device, resetting the page number. So, by plotting one plot per bitmap call, you are always writing to foo0001.jpg.

Instead, call bitmap just once:

bitmap("foo%03d.jpg")
for (i in 1:5) {
     plot(runif(20), ylim = c(0, 1))
}
dev.off()
Sign up to request clarification or add additional context in comments.

1 Comment

wow, it works! This is my first time to ask question here. I'm so happy to get reply so quick. Thank you sooo much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.