M.C. Park
M.C. Park

Reputation: 305

How to display a sequence of plots successively with some pause in R?

Consider the simple example below:

> x <- matrix(NA, 20, 5)
> y <- matrix(NA, 20, 5)
> for (i in 1:5) {
        x[, i] <- rnorm(20)
        y[, i] <- rnorm(20)
}

Here, I wanted to examine the scatter plot of each column of x and y. Thus, I tried to the following loop:

for (j in 1:5) {
        plot(x[, j], y[, j])
}

But, as you expect, the result is just plot(x[, 5], y[, 5]).

In particular, my goal is to see plot(x[, 1], y[, 1]) for ten seconds, and then see plot(x[, 2], y[, 2]) for ten seconds, and so on.

How can I do this work?

Upvotes: 0

Views: 182

Answers (1)

M.C. Park
M.C. Park

Reputation: 305

One possible solution could be

for (j in 1:5) {
        plot(x[, j], y[, j])
        Sys.sleep(10)
}

Upvotes: 1

Related Questions