Teresa Fish
2010-Mar-01 23:56 UTC
[R] Saving multiple plots named with part of the original file name
Hello All,
I am trying to open all files within a folder and create multiple histograms
from each file, *and* have it save with the original file name plus some new
information. The way I have it set up right now, I keep saving over each new
graph. I can turn the history on and see them all, but I want them all to
save as unique files as well. Idealy they would be "filename CHN 1mm Length
Frequency", "filename CHN 2mm Length Frequency"...and so forth.
Any hints?
Thanks for your time.
Here is what I'm using now:
filenames<-dir("C:/Documents and Settings/tfish/Desktop/R/Untilted
Data")
for(i in filenames){data<- read.csv(i, header = TRUE, skip = 13, sep =
",")
hist(data$X.mm.[data$SPP=="RBT"],breaks=seq(20,350,1),col="blue",main="RBT
1mm Length Frequency",freq=TRUE,xlab="Fork Length (mm)")
savePlot(filename = "RBT 1mm Length Frequency",type =
c("jpg"))
hist(data$X.mm.[data$SPP=="RBT"],breaks=seq(20,350,2),col="blue",main="RBT
2mm Length Frequency",freq=TRUE,xlab="Fork Length (mm)")
savePlot(filename = "RBT 2mm Length Frequency",type =
c("jpg"))
Thanks again for any and all help!
--
T Fish
[[alternative HTML version deleted]]
jim holtman
2010-Mar-02 00:36 UTC
[R] Saving multiple plots named with part of the original file name
You need to differentiate between the file names. Try concatentating
on the source file: using 'paste'
filenames<-dir("C:/Documents and Settings/tfish/Desktop/R/Untilted
Data")
for(i in filenames){data<- read.csv(i, header = TRUE, skip = 13, sep =
",")
hist(data$X.mm.[data$SPP=="RBT"],breaks=seq(20,350,1),col="blue",main="RBT
1mm Length Frequency",freq=TRUE,xlab="Fork Length (mm)")
savePlot(filename = paste(i, "RBT 1mm Length Frequency"),type =
c("jpg"))
hist(data$X.mm.[data$SPP=="RBT"],breaks=seq(20,350,2),col="blue",main="RBT
2mm Length Frequency",freq=TRUE,xlab="Fork Length (mm)")
savePlot(filename = paste(i,"RBT 2mm Length Frequency"),type =
c("jpg"))
On Mon, Mar 1, 2010 at 6:56 PM, Teresa Fish <fishtm at gmail.com>
wrote:> Hello All,
> I am trying to open all files within a folder and create multiple
histograms
> from each file, *and* have it save with the original file name plus some
new
> information. The way I have it set up right now, I keep saving over each
new
> graph. I can turn the history on and see them all, but I want them all to
> save as unique files as well. Idealy they would be "filename CHN 1mm
Length
> Frequency", "filename CHN 2mm Length Frequency"...and so
forth. Any hints?
> Thanks for your time.
> Here is what I'm using now:
>
> filenames<-dir("C:/Documents and Settings/tfish/Desktop/R/Untilted
Data")
> for(i in filenames){data<- read.csv(i, header = TRUE, skip = 13, sep =
",")
>
hist(data$X.mm.[data$SPP=="RBT"],breaks=seq(20,350,1),col="blue",main="RBT
> 1mm Length Frequency",freq=TRUE,xlab="Fork Length (mm)")
> savePlot(filename = "RBT 1mm Length Frequency",type =
c("jpg"))
>
hist(data$X.mm.[data$SPP=="RBT"],breaks=seq(20,350,2),col="blue",main="RBT
> 2mm Length Frequency",freq=TRUE,xlab="Fork Length (mm)")
> savePlot(filename = "RBT 2mm Length Frequency",type =
c("jpg"))
> Thanks again for any and all help!
> --
> T Fish
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?