1 # MvA plotting for microarray data
4 # Copyright 2003 By Don Armstrong
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 # $Id: mva_plotting.R,v 1.5 2006/06/10 04:14:45 don Exp $
28 # Plots a pairwise M versus A plot with a loess fit line
29 ##' Plots a pairwise M versus A plot with a loess fit line
31 ##' .. content for \details{} ..
32 ##' @title mva.plot.pair
33 ##' @param array Array of data to plot
34 ##' @param title Title of plot (Default: FALSE; no title)
35 ##' @param small.positive replace numbers less than 0 with this
36 ##' @author Don Armstrong \email{don@@donarmstrong.com}
37 mva.plot.pair <- function(array,title=FALSE,small.positive=0.1){
39 npair <- size*(size-1)/2
40 height <- min(round((npair*3/4)^0.5),3)
41 width <- min(ceiling(npair/height),3)
42 def.par <- par(no.readonly = TRUE)
43 mva.layout <- grid.layout(ncol=width,nrow=height)
44 pushViewport(viewport(layout=mva.layout))
45 ## we could also use combn here instead
49 num.plot <- num.plot + 1
52 group.keep <- is.finite(group.1) & is.finite(group.2)
53 group.1 <- group.1[group.keep]
54 group.2 <- group.2[group.keep]
55 group.min <- min(c(group.1,group.2))
57 group.1 <- group.1 - group.min + small.positive
58 group.2 <- group.2 - group.min + small.positive
60 A <- 0.5*log2(group.1*group.2)
61 M <- log2(group.1/group.2)
62 temp.frame <- na.omit(data.frame(cbind(A,M)))
64 floor((num.plot -1)/ width) %% height == 0 &&
65 (num.plot-1) %% width == 0) {
67 grid.text(title,x=unit(0.0,"npc")+unit(1,"lines"),y=unit(0.5,"npc"),just="center",rot=90)
69 pushViewport(viewport(layout=mva.layout))
71 ## print(floor((num.plot -1)/ width) %% height+1)
72 ## print((num.plot - 1)%% width+1)
73 print(ggplot(temp.frame,aes(y=M,x=A))+
75 stat_smooth(method="gam")+
76 ggtitle(paste0(colnames(array)[a],"\nvs\n",colnames(array)[b]))+
77 theme(legend.position="none"),
78 vp=viewport(layout.pos.row=floor((num.plot -1)/ width) %% height+1, layout.pos.col=((num.plot - 1)%% width+1)))