【问题标题】:Problems saving several pdf files in R在 R 中保存多个 pdf 文件时出现问题
【发布时间】:2012-10-18 08:27:17
【问题描述】:

我正在尝试在 R 中保存几个使用“for”循环创建的 xyplots,如果我执行以下循环:

for (i in 1:length(gases.names)) {
   # Set ylim;
   r_y <- round(range(ratio.cal[,i][ratio.cal[,i]<999], na.rm = T), digits = 1);
   r_y <- c(r_y[1]-0.1, r_y[2]+0.1);

   outputfile <- paste (path, "/cal_ratio_",gases.names[i], ".pdf", sep="");
   dev.new();
   xyplot(ratio.cal[,i] ~ data.GC.all$data.time, groups = data.vial, panel = 
      panel.superpose, xlab = "Date", ylab = gases.names[i], xaxt="n", ylim = r_y);
   savePlot(filename = outputfile, type = 'pdf', device = dev.cur());
   dev.off();
}

(以前的版本使用trellis.device() 而不是dev.new() + savePlot()

你知道为什么我不能得到好的 pdf 文件吗?如果我“手动”执行它,它会起作用...有什么想法吗?

【问题讨论】:

    标签: r pdf save


    【解决方案1】:

    直接使用pdf

    for (i in seq_along(gases.names)) {
      # Set ylim
      r_y <- round(range(ratio.cal[,i][ratio.cal[,i]<999], na.rm = T), digits = 1)
      r_y <- c(r_y[1]-0.1, r_y[2]+0.1)
    
       outputfile <- paste (path, "/cal_ratio_",gases.names[i], ".pdf", sep="")
       pdf(file = outputfile, width = 7, height = 7)
       print(xyplot(ratio.cal[,i] ~ data.GC.all$data.time, groups = data.vial, 
                     panel =  panel.superpose, xlab = "Date", ylab = gases.names[i], 
                     xaxt="n", ylim = r_y))
    
      dev.off()
    
    }
    

    【讨论】:

    • 注意print的使用,与FAQ's这个最频繁的使用有关。
    猜你喜欢
    • 2019-03-26
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多