0

I am trying to create several plots and save each one as a png file with a particular name. I have created a function that is called in a loop which runs through a list of different environmental names. I would like the file name to be the same as the environmental name. However, when running the script, no files are created and I cannot locate the problem.

myDF.2 = ddply(myDF, .(ENVIRONMENT, FILENAME), summarize, MGC= mean(T, na.rm=TRUE) )

PLOT_ENVIRONMENTS = function(labelname)
{
   png(filename = paste('/blah/blah/path/', labelname, '.png', sep=''))
   meanDFF = myDF.2[(myDF.2$ENVIRONMENT==labelname), ]
   g <- ggplot(meanDFF, aes(FILENAME, MGC))
   g <- g + labs(title=labelname)
   g <- g + ylim(c(10, 90)) + theme(axis.text = NULL)
   g + geom_point(aes(colour=factor(FILENAME))) + theme(axis.text.x=element_text(angle=90, hjust=1))
   dev.off()
}

environments = unique(unlist(myDF$ENVIRONMENT, use.names = FALSE))
for (i in environments)
{
   PLOT_ENVIRONMENTS(i)
}

I know the code below works, but as I have ~30 environmental variables, I was looking for something more streamlined.

png(filename='/blah/blah/path/Microbialites.png')
PLOT_ENVIRONMENTS('Microbialites')
dev.off()
png(filename='/blah/blah/path/Water_Marine.png')
PLOT_ENVIRONMENTS('Water_Marine')
dev.off()

Suggestions appreciated.

cer
  • 1,961
  • 2
  • 17
  • 26

0 Answers0