+ ggplot 中的符号/字符干扰 for 循环。任何人都知道如何解决它?

问题描述 投票:0回答:0
for (i in 2:ncol(Dat.Db)){ 
  VarNAME <- colnames(Dat.Db[i]) # pull column names

  pdf(file = paste(VarNAME,".pdf", sep=""), height=8, width=8) #starts a pdf file with the name of the   elements

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

  #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() 
} 

我正在尝试运行一个简单的循环以使用 ggplot(#Plot1 代码)生成箱线图的 pdf 导出,但是,pdf 正在使用#Plot1 代码生成空白。我相信这与 ggplot 中的加号“干扰”循环有关,我不知道如何解决。我添加了#Plot 2 代码以进行比较,该代码似乎确实有效。谁能帮我修复#Plot1 代码?提前谢谢你。

for-loop ggplot2 boxplot ggboxplot
© www.soinside.com 2019 - 2024. All rights reserved.