1
for (i in 2:ncol(Dat.Db)){ 
  VarNAME <- colnames(Dat.Db[i]) # pull column names
  #starts a pdf file with the name of the   elements
  pdf(file = paste(VarNAME,".pdf", sep=""), height=8, width=8) 

  # mfcol sets up a 2x2 grid to drop figures in
  par(mfcol=c(2,1), mar=c(4,4,2,2))
  

  #Plot1 ggplot function {ggplot2}
  ggplot(Dat.Db, aes(x = Strat_Sym, y = Dat.Db[, i], fill = Strat_Sym)) +
    stat_boxplot(geom = "errorbar", # Error bars
             width = 0.25) +    # Bars width
    theme(axis.text.x = element_text(angle = -90, vjust = 0.5, hjust=0)) + 
    geom_boxplot()

  #Plot2 boplot function {graphics}
   boxplot(Dat.Db[,i]~ Strat_Sym, Dat.Db)

  dev.off() 
} 

I am trying to run the a simple loop to generate pdf exports of boxplots using ggplot (#Plot1 code), however, the pdfs are being generated blank using #Plot1 code. I believe it has to do with the plus sings in ggplot "interfering" with the loop, and I do not know how to fix that. I have added #Plot 2 code for comparison, and that one does seem to work. Could anyone help me fix #Plot1 code ? Thank you in advance.

akrun
  • 874,273
  • 37
  • 540
  • 662
Tony
  • 11
  • 2

0 Answers0