0

I'm trying to save multiple png files (plots) in R and am not able to save any file whatsoever.

I've already read up on a similar solution here:

http://www.r-bloggers.com/automatically-save-your-plots-to-a-folder/

And essentially I've implemented the same idea, I just can't get it to run.

Here's some of my data, a data frame called "new_bic":

              time  electrode   amps 
  3321    11.33760     A1_21    0.02445126
  3322    11.33792     A1_85    0.02156030 
  3323    11.33844     A1_82    0.02739474
  3324    11.33876     A1_57    0.02715583
  3325    11.33920     A1_47    0.02292635
  3326    11.33976     A1_68    0.02581157
  3327    11.34032     A1_21    0.03866543
  3328    11.34060     A1_28    0.02337550
  3329    11.34104     A1_53    0.03956954
  3330    11.34216     A1_57    0.04843832

This is a simple segment of my data. But I'm making simple line graphs for each electrode. Each electrode will have a "amp" recording about every few milliseconds.

Anyways here's the code I was running to print of a single plot and it works fine, and will save the plot in my current working directory. For example let's say I wanted to a plot for the electrode "A1_21" this is what I would do:

 elec <- "A1_21"
 new_data <- new_bic[new_bic$electrode == elec,]
 png(paste(elec,".png",""))
 new_p <- ggplot(new_data, aes(x=time, y=amps))
 new_p + ggtitle(elec) +geom_line()
 dev.off()

And this works just fine. But there are actually 62 electrodes, so what I really want is something like this

 for (sel_electrode in unique(new_bic$electrode))
 {
 new_data <- new_bic[new_bic$electrode == sel_electrode,]
 png(paste(sel_electrode,".png",""))
 new_p <- ggplot(new_data, aes(x=time, y=amps))
 new_p + ggtitle(sel_electrode) +geom_line()
 dev.off()
 }

But this does NOT work. When I run this code NOTHING is printed. I feel as if this is very very trivial. I'm sending out an SOS.

Doug
  • 597
  • 2
  • 7
  • 22

0 Answers0