[R] Scripting graph generation
Rajarshi Guha
rguha at indiana.edu
Wed Apr 25 20:13:56 CEST 2007
On Wed, 2007-04-25 at 13:21 -0400, Mike Huber wrote:
> Hi,
>
> I'm looking to automate the generation of some graphs in R. I can't seem to
> figure out how to script R, and change the output device of hist() or plot()
> to create a .gif or .png file. This seems like something that is probably
> really simple, and I've just overlooked the call do do it. Can anyone point
> me in the right direction, or maybe send a sample script?
To plot multiple PNG files
m <- matrix(runif(100*10), nrow=10)
png(filename = 'plot%03d.png')
for (i in 1:nrow(m)) {
plot(m[i,])
}
dev.off()
To plot multiple graphs as individual pages of a PDF file
m <- matrix(runif(100*10), nrow=10)
pdf(file = 'plot.pdf')
for (i in 1:nrow(m)) {
plot(m[i,])
}
dev.off()
HTH,
-------------------------------------------------------------------
Rajarshi Guha <rguha at indiana.edu>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
In matrimony, to hesitate is sometimes to be saved.
-- Butler
More information about the R-help
mailing list