2012-10-29 4 views
3

"for"루프로 작성한 여러 xyplot을 R에 저장하려고하는데 전체 PDF 파일을 가져올 수 없습니다 (모든 파일의 크기는 같고 읽을 수 없습니다). 나는 좋은 PDF 파일을받을 수없는 이유여러 PDF 파일을 저장할 때의 문제 R

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()의를 사용했다

당신은 알고 계십니까 : 나는 다음과 같은 루프를 실행하는 경우)을 열? 만약 내가 "수동으로"그것을 작동 ... 어떻게 생각하십니까?

답변

5

사용 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() 

} 
+4

참고 [FAQ]의이 가장 빈번하게 관련된 print' '의 사용 (http://cran.r-project.org/doc/FAQ/R-FAQ .html # Why-do-lattice_002ftrellis-graphics-not-work_003f). – joran

관련 문제