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
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…