2012-04-20 31 views
2

我有下面的代码产生多条曲线,在每一个单独的PDF文件如何标签添加到文件中产生多个地块代码

myplot <-function(ind,dfList) { 
dat <- dfList[[ind]] 
    detects <- as.numeric(dat$Result2[dat$cens== 0]) 
    pdf(file=paste("Desktop/qqplot_",ind,".pdf",sep = "")) 
    qqnorm(log(detects), ylab="Ln of uncensored data in ppm", main="Q-Q plot", pch=16) 
    qqline(log(detects)) 
      dev.off() 
      } 

Plots <- lapply(1:3, myplot , dfList = mydata) 

问题1:此代码生成3个PDF文件。这些文件的标签是1,2和3.如何插入一个代码,将每个文件重新标签为图X,图Y,图Z.

问题2:在我的myplot函数中,图的标题是QQ图但我想改变文件名称对应的标题。所以每个小区的标题应该是小区X,小区Y,小区Z.

+2

由于您未提供任何数据,因此您的代码无法复制。根据代码(不运行),它看起来像这些文件将是'qqplot_1','qqplot_2'等名称。您需要调整您的代码行,以'pdf(...'开头)。 ,你可以使用'main ='来调整剧情的标题,无论你想在这里说什么'参数',你可能需要使用'paste()',就像你在上面一行所做的那样,以引用变量/列值... – Chase 2012-04-20 18:02:38

回答

4

未测试由于没有虚拟数据,但应该有效。

myplot <- function(ind,dfList) { 
    # Add a vector of labels 
    # then use index at will to build plot and title strings etc 
    labels <- c("X", "Y", "Z") 
    myfilename <- paste("Desktop/qqplot_",labels[ind],".pdf",sep = "") 
    mytitle <- paste("Plot ",labels[ind],sep = "") 

    dat <- dfList[[ind]] 
    detects <- as.numeric(dat$Result2[dat$cens== 0]) 
    pdf(file=myfilename) 
     qqnorm(log(detects), ylab="Ln of uncensored data in ppm", main=mytitle, pch=16) 
     qqline(log(detects)) 
    dev.off() 
} 

Plots <- lapply(1:3, myplot , dfList = mydata) 
+0

看起来应该可以工作,也可以尝试使用',title = bquote(Plot〜。(c(“X”,“Y”,“Z”)[ind])) ' – 2012-04-20 20:45:58

+0

@ gauden。是的,谢谢。 – Amateur 2012-04-20 22:11:50

相关问题