显示wilcox测试结果以及PDF图

时间:2011-04-03 13:13:32

标签: r

我写了一个函数,它将为每个类的数据生成一个图,我还创建了一个函数,它将对所有类和每个类执行wilcox测试。

我想要做的是获取此测试的结果,并将其显示在每个类的每个特定PDF中。这可以用很好的方式完成吗?

这是我用来执行wilcox测试的函数的代码:

library(ggplot2)
t = read.table("data.txt", stringsAsFactors=FALSE)
uni = unique(c(t$V9))

testresult<- function(column, datacol) {    
  if(column=="PP") {
    for (xp in uni) { 
      for(yp in uni) {
        testx<- subset(t, V9==xp)
        testy<- subset(t, V9==xp)
        zz = wilcox.test(testx[[datacol]],jitter(testy[[datacol]]))
        print(p1)
        p1 = c(xp)
        p2 = c(yp)
        pv = c(zz$p.value)
      }
    }
  } 
}
for (x in uni) { 
  test<-subset(t, V9==x)
  dat <- melt(test, measure=c("V1", "V2" , "V3" , "V4"))

  p <- ggplot(dat, aes(Class,value , color=variable)) + 
       geom_boxplot() + 
       geom_point(position="jitter" , alpha=0.3) +  
       facet_grid(variable~., scales="free_y")
       ggsave(paste("ggplot2/",paste(x,".pdf")), p, width=25, height=15)
}

我试图在列表中或数据框内填充它,但它没有那样工作。

2 个答案:

答案 0 :(得分:1)

您可能希望使用Sweave生成混合文本和图表的精美PDF报告。

答案 1 :(得分:1)

您想在每个地块中显示它?作为标题,在情节区域内注释?这里有一些选择。

#No sample data provided, so we use this instead.
dat <- data.frame(x = rnorm(100), y = rnorm(100))

ggplot(dat , aes(x,y)) + 
geom_point() +
opts(title = "hi world") +  #This line makes a title
geom_text(aes(max(x),max(y), label=paste("The mean of x = ", round(mean(x),3), sep = " ")), hjust = 1, size = 3)     #This line annotates within the plot region