## Animations generated in R version 2.15.2 (2012-10-26) using the package animation
library(scales)
library(animation)
library(ggplot2)
library(devtools)
library(nnet)
library(clusterGeneration)
library(MASS)
for (i in 1:num.it) {
    mod.tmp <- nnet(rand.vars[train.dat, ], y[train.dat, 
        , drop = F], size = 10, linout = T, maxit = i, trace = F)
    pred.vals <- predict(mod.tmp, new = rand.vars)
    sub.fac <- rep("test", length = num.obs)
    sub.fac[train.dat] <- "training"
    sub.fac <- factor(sub.fac, c("training", "test"))
    plot.tmp <- data.frame(cbind(sub.fac, pred.vals, y))
    names(plot.tmp) <- c("Group", "Predicted", "Observed")
    title.val <- paste("Iteration", i, "of", num.it)
    rmse.val <- data.frame(Group = factor(levels(sub.fac), 
        c("training", "test")), rmse = paste("rmse =", c(rmse.fun(pred.vals, 
        train.dat), rmse.fun(pred.vals, !train.dat))), x.val = rep(0.9, 
        2), y.val = rep(0.1, 2))
    p.tmp <- ggplot(data = plot.tmp, aes(x = Observed, y = Predicted, 
        group = Group, colour = Group)) + geom_abline() + 
        geom_point(size = 6, alpha = 0.5) + scale_x_continuous(limits = c(0, 
        1)) + scale_y_continuous(limits = c(0, 1)) + facet_grid(. ~ 
        Group) + theme_bw() + colScale + geom_text(data = rmse.val, 
        aes(x = x.val, y = y.val, label = rmse, group = Group), 
        colour = "black", size = 4) + ggtitle(title.val) + 
        theme(plot.title = element_text(vjust = 2, size = 18), 
            legend.position = "none")
    print(p.tmp)
}
## R version 2.15.2 (2012-10-26)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Other packages: scales 0.2.3, animation 2.1,
## ggplot2 0.9.3, devtools 1.1, nnet 7.3-5,
## clusterGeneration 1.3.1, MASS 7.3-23