0

I am trying to save different PCA plots together in one PDF. I have tested the myPCs matrix and also plotted a few plots via the command line and it works from there.

*** I would like to have all the nine plots below in a single PDF file (9pages)

PCAPlots <-function(Object){
    beta<-getBeta(Object)
    beta <-t(beta)
    myPCA=prcomp(beta,scale.=TRUE,center=TRUE)
    myPCs=data.frame(myPCA$x)
    pdf("PCA.pdf")     
    qplot(PC2,PC1,data=myPCs,colour=pheno$sex)
    qplot(PC3,PC2,data=myPCs,colour=pheno$sex)
    qplot(PC4,PC3,data=myPCs,colour=pheno$sex)
    qplot(PC2,PC1,data=myPCs,colour=pheno$age)
    qplot(PC3,PC2,data=myPCs,colour=pheno$age)
    qplot(PC4,PC3,data=myPCs,colour=pheno$age)
    qplot(PC2,PC1,data=myPCs,colour=pheno$treatment)
    qplot(PC3,PC2,data=myPCs,colour=pheno$treatment)
    qplot(PC4,PC3,data=myPCs,colour=pheno$treatment)
    dev.off()
}
myPlots <-PCAPlots(Object)
Praveen Reddy
  • 7,295
  • 2
  • 21
  • 43
Mdhale
  • 815
  • 2
  • 15
  • 22
  • 1
    Clarify, please, whetehr you are looking for a multipage result. It appears so, and the answer is probably R-FAQ 7.22. – IRTFM Feb 20 '17 at 23:14
  • Do you need all nine plots on a single page? Or all nine plots on the same file? – Yuri-M-Dias Feb 20 '17 at 23:16
  • Please look at the edit. thanks – Mdhale Feb 20 '17 at 23:25
  • Did you look at the FAQ? – IRTFM Feb 21 '17 at 00:01
  • Yes I did. It seems for qplot(ggplot2) I would have to assign a variable to the individual qplot's.And then print it. Something like: p1<- qplot(PC2,PC1,data=myPCs,colour=pheno$sex) p2<- qplot(PC3,PC2,data=myPCs,colour=pheno$sex) and then print(p1,p2). Do you think this is right? – Mdhale Feb 21 '17 at 00:50
  • Maybe, although I'm dubious about `print()` with those two arguments. Look at at ?print and ?print.ggplot and I think you will find that its second argument is not a grid object. Generally one would need `lapply(list_of_grid_objects, print)`. Your first name isn't Cliff, by any chance? – IRTFM Feb 21 '17 at 03:10

0 Answers0