Skip to content

Instantly share code, notes, and snippets.

@cdesante
Created July 13, 2012 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdesante/3107543 to your computer and use it in GitHub Desktop.
Save cdesante/3107543 to your computer and use it in GitHub Desktop.
Looping over plots with GGPLOT
#Set the working directory, plots will be saved locally.
library(ggplot2)
X <- rnorm(100)
Y <- rnorm(100)
Z <- rnorm(100)
A <- rnorm(100)
B <- rnorm(100)
my.variables <- cbind(Y, Z, A, B)
dim(my.variables)
for (i in 1:dim(my.variables)[2]) {
qplot(X, my.variables[,i], geom="point")
ggsave( filename=print(paste("plot", i, ".pdf")) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment