Question: I would like to loop through a long series of `qplots` or `ggplot2` plots, pausing at each one so I can examine it before moving on.

The following code produces no plots:

```
library(ggplot2)
par(ask=TRUE)
for(Var in names(mtcars)) {
    qplot(mtcars[,Var], wt, data=mtcars, xlab=Var)
}

```

but if I run this line after running the loop, I DO get a plot:

```
qplot(mtcars[,Var], wt, data=mtcars, xlab=Var)

```

What is the reason for this behavior? How do I display the plots within the loop?

Follow up:
Is there a more elegant way to loop through the variables than using `mtcars[,Var]` and `xlab=Var`?

Answer: 
As the other answers have said, wrap each `qplot()` call in `print()` (this is [R FAQ 7.22](http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f)). The reason why is that ggplot's aren't printed to the graphics device until `print.ggplot` is called on them. `print()` is a generic function that dispatches to `print.ggplot` behind the scenes. 

When you are working in the repl ("read-evaluate-print loop", aka shell) the return value of the previous input line is automatically printed via an implicit call to `print()`. That's why 
`qplot(mtcars[,Var], wt, data=mtcars, xlab=Var)` is working for you. It's nothing to do with scope or the for loop. If you were to put that line anywhere else that isn't directly returning to the repl, such as in a function that returns something else, it would do nothing.
Add `print`:

```
library(ggplot2)
par(ask=TRUE)
for(Var in names(mtcars)) {
    print(qplot(mtcars[,Var], wt, data=mtcars, xlab=Var))
}

```

For an explanation see Tavis Rudd's answer.