I want to plot a bunch of variables against each other by using a loop and par(ask=T) to just update the plot after each mouse click.
The following code works fine using the plot() function:
require(ggplot2)
df1 <- data.frame(id=seq(1,10,1)
,col1 = runif(10)
,col2 = runif(10)
,col3 = runif(10)
,col4 = runif(10)
,col5 = runif(10)
,col6 = runif(10)
,col7 = runif(10)
,col8 = runif(10)
,col9 = runif(10)
,col10 = runif(10)
)
par(ask=TRUE)
for(i in 2:9){
colName2 <- paste("col",i,sep="")
plot(df1$col1, df1[,colName2])
flush.console()
}
par(ask=FALSE)
However if I run the same code and use qplot() instead of plot(), the plot window never updates.
Any ideas why or workarounds?
ggplot2graphs are not displayed just by a call toqplot(orggplot); when the value returned by this function is printed (as it is by default when issued on the command line), then the plot is drawn. Within a loop, the return value of a function is not printed by default, so nothing is shown. Explicitly print it, and it will show up.This is covered in R FAQ 7.22.