RDX2 X  slide.image source =function (z, layout, crit1 = 0.05, crit2 = crit1, bar.side=2, D lohi.colors=c("#9E0142","#D53E4F","#F46D43","#FDAE61", 7 "#ABDDA4","#66C2A5","#3288BD","#5E4FA2"), C nacolor="#FFFF00", boxplot.side=1, split="quantiles") {  "block2matrix" <- , function(z, sr=3, sc=2, gr=2, gc=2){ D ## Assumes that values in the vector z are in row major D ## order within blocks of dimension sr x sc, with blocks B ## in row major order within a gr x gc array of grids. A ## Elements in the vector that is returned are in row D ## major order wrt the sr*gr x sc*gc matrix of values on C ## the slide. (It is given the dimensions of a matrix.) 1 xy <- array(z, dim=c(sc, sr, gc, gr)) ' xy <- aperm(xy, c(1,3,2,4)) & dim(xy) <- c(sc*gc, gr*sr)  xy} % quantile.na <- function (z, ...)   { + tmp <- !(is.na(z) | is.infinite(z))  quantile(z[tmp], ...)  } # length.na <- function (z, ...)   { + tmp <- !(is.na(z) | is.infinite(z))  length(z[tmp], ...)  } ) bplot <- function(z, boxplot.side=1){ % xrange <- range(z,na.rm=TRUE) 1 iqr <- diff(quantile(xrange, c(.25,.75))) $ bwex <- diff(xrange)/(3*iqr) xhi <- max(z,na.rm=TRUE) ! xusr <- par()$usr[c(1:2)] & xpos=pretty(z[!is.na(z)], n=5) : z <- xusr[1]+(z-xrange[1])*diff(xusr)/diff(xrange) B newpos <- xusr[1]+(xpos-xrange[1])*diff(xusr)/diff(xrange)  par(xpd=TRUE) E atvert <- switch(boxplot.side, par()$usr[3]-par()$cxy[2]*0.8, ? "", par()$usr[4]+par()$cxy[2]*0.8, "")  if(atvert!=""){ M boxplot(z, at=atvert, boxwex=bwex, add=T, horizontal=T, xaxt="n") - axis(side=boxplot.side, line=1.5, I at=newpos, labels=xpos, cex.axis=0.75, mgp=c(2, 0.5, 0)) }  par(xpd=FALSE)  }  if (crit1 >= 1)  % crit1 <- crit1/(length.na(z))  if (crit2 >= 1)  % crit2 <- crit2/(length.na(z)) = tmpind <- (z > quantile.na(z, probs = 1 - crit2)) | (z <  @ quantile.na(z, probs = crit1))  n <- prod(unlist(layout))  n.all <- length(z)  n.na <- sum(is.na(z)) $ nhalf <- length(lohi.colors)%/%2  n2 <- 2*nhalf n.one <- length(lohi.colors) plo <- crit1*(0:nhalf)/nhalf " phi <- 1-crit2*(nhalf:0)/nhalf " quiles1 <- quantile.na(z, plo) " quiles2 <- quantile.na(z, phi)  if(split=="intervals"){ E quiles1[2:nhalf] <- quiles1[1]+(quiles1[nhalf+1]-quiles1[1])*  (1:(nhalf-1))/nhalf E quiles2[2:nhalf] <- quiles2[1]-(quiles2[nhalf+1]-quiles2[1])*  ((nhalf-1):1)/nhalf & plo[-1] <- sapply(quiles1[-1], M function(x, z)sum(z<=x, na.rm=T)/length.na(z), z=z) & phi[-1] <- sapply(quiles2[-1], M function(x, z)sum(z<=x, na.rm=T)/length.na(z), z=z)  }    if(crit1+crit2<1){ $ quiles <- c(quiles1,quiles2)  frac <- c(plo, phi) 3 colpal <- c(lohi.colors[1:nhalf],"#FFFFFF", 9 lohi.colors[(n.one-nhalf+1):(n.one)])  midbreak <- TRUE  }  else {colpal <- lohi.colors  midbreak <- FALSE 3 quiles <- quantile.na(z, (0:n.one)/n.one) ! frac <- c(plo, phi[-1])  }  dups <- duplicated(quiles)  if(any(dups)){ % cats <- seq(along=quiles[-1]) ! filledcats <- cats[!dups] I cutcats <- as.integer(cut(z, quiles[!dups], include.lowest=TRUE)) % fullm <- filledcats[cutcats]} A else fullm <- as.integer(cut(z, quiles, include.lowest=TRUE))  n.one <- length(colpal)  nrects <- length(quiles)  if(any(is.na(z))){  nacat <- TRUE B fullm[is.na(fullm)] <- max(unique(fullm[!is.na(fullm)]))+1 $ colpal <- c(colpal, nacolor)  }  else nacat <- FALSE = if ((length(as.vector(z)) != n) & (!is.null(names(z)))) {  y <- fullm[tmpind]  fullm <- rep(NA, n) ( fullm[as.integer(names(y))] <- y  }  else fullm[!tmpind] <- NA < if ((length(as.vector(z)) != n) & (is.null(names(z)))) { n stop(" Error: Length of vector is different from total number of spots and vector has no row.name.\n")  } A#################################################################  gc <- layout$ngrid.c  gr <- layout$ngrid.r  sc <- layout$nspot.c  sr <- layout$nspot.r / full <- block2matrix(fullm, sr, sc, gr, gc) = image(1:ncol(full), 1:nrow(full), t(full), axes = FALSE,  + xlab = "", ylab = "", col=colpal) box() ) abline(v = ((gr - 1):1) * (sr) + 0.5) ) abline(h = (1:(gc - 1)) * (sc) + 0.5) A################################################################# A if(boxplot.side%in%c(1,3))bplot(z, boxplot.side=boxplot.side)  if(bar.side%in%c(2,4)){  chw <- par()$cxy[1]  barwid <- 0.75*chw  if(bar.side==2){ ) x0 <- par()$usr[1]-chw-barwid # xcutpos <- x0 - 0.4*chw + xquilepos <- x0+barwid+0.55*chw  srt <- 90 }  else { " x0 <- par()$usr[2]+chw , xcutpos <- x0 + barwid + 0.4*chw # xquilepos <- x0-0.4*chw  srt <- -90 } 9 yvals2 <- seq(from=par()$usr[3], to=par()$usr[4], M length=n2+midbreak+2*nacat+1)[-(n2+midbreak+2*nacat+1)] ! eps2 <- diff(yvals2[1:2])    if(nacat){ # nlast <- length(yvals2) $ nclast <- length(colpal) B rect(x0, yvals2[nlast], x0+barwid, yvals2[nlast]+eps2, + col=colpal[nclast], xpd=T) = text(x0+0.5*barwid, yvals2[nlast]+0.5*eps2, "NA", # xpd=TRUE, srt=srt) 0 yvals2 <- yvals2[-((nlast-1):nlast)] % colpal <- colpal[-nclast] }  if(!midbreak){ 4 rect(x0, yvals2, x0+barwid, yvals2+eps2, # col=colpal, xpd=T) 3 text(xcutpos, c(yvals2[1],yvals2+eps2), E paste(signif(quiles,3)), srt=srt, xpd=TRUE, cex=0.8) K text(xquilepos, yvals2[1], "(0%)", srt=srt, xpd=TRUE, cex=0.65) . fracs <- frac[-c(1, length(frac))] ' text(xquilepos, yvals2[-1], : paste("(",round(fracs*100,2),")",sep=""), - srt=srt, xpd=TRUE, cex=0.65) K text(xquilepos, yvals2[length(yvals2)]+eps2, "(100%)", srt=srt, $ xpd=TRUE, cex=0.65)  } H else {rect(x0, yvals2[1:nhalf], x0+barwid, yvals2[1:nhalf]+eps2, . col=colpal[1:nhalf], xpd=T) @ rect(x0, yvals2[(nhalf+2):(2*nhalf+1)], x0+barwid, 6 yvals2[(nhalf+2):(2*nhalf+1)]+eps2, < col=colpal[(nhalf+2):(2*nhalf+1)], xpd=T) 0 text(xcutpos, yvals2[1:(nhalf+1)], H paste(signif(quiles1,3)), srt=srt, xpd=TRUE, cex=0.8) 2 text(xquilepos, yvals2[2:(nhalf+1)], G paste("(",round(plo[-1]*100,2),")",sep=""), srt=srt, & xpd=TRUE, cex=0.65) M text(xquilepos, yvals2[1], "(0%)", srt=srt, xpd=TRUE, cex=0.65)  text(xcutpos, L c(yvals2[(nhalf+2):(2*nhalf+1)], yvals2[2*nhalf+1]+eps2), H paste(signif(quiles2,3)), srt=srt, xpd=TRUE, cex=0.8) < text(xquilepos, yvals2[(nhalf+2):(2*nhalf+1)], H paste("(",round(phi[-length(phi)]*100,2),")",sep=""), / srt=srt, xpd=TRUE, cex=0.65) H text(xquilepos, yvals2[2*nhalf+1]+eps2, "(100%)", srt=srt, & xpd=TRUE, cex=0.65) }  }  invisible() } z layout crit1? crit2 bar.side@ lohi.colors c #9E0142 #D53E4F #F46D43 #FDAE61 #ABDDA4 #66C2A5 #3288BD #5E4FA2 nacolor #FFFF00 boxplot.side? split quantiles { <- block2matrix function sr@ sc@ gr@ gc@  xy array dim  aperm ?@@@  *  $function(z, sr=3, sc=2, gr=2, gc=2){ D ## Assumes that values in the vector z are in row major D ## order within blocks of dimension sr x sc, with blocks B ## in row major order within a gr x gc array of grids. A ## Elements in the vector that is returned are in row D ## major order wrt the sr*gr x sc*gc matrix of values on C ## the slide. (It is given the dimensions of a matrix.) 1 xy <- array(z, dim=c(sc, sr, gc, gr)) ' xy <- aperm(xy, c(1,3,2,4)) & dim(xy) <- c(sc*gc, gr*sr)  xy} quantile.na ...  tmp ! ( | is.na is.infinite quantile [ function (z, ...)   { + tmp <- !(is.na(z) | is.infinite(z))  quantile(z[tmp], ...)  } length.na  ! length# function (z, ...)   { + tmp <- !(is.na(z) | is.infinite(z))  length(z[tmp], ...)  } bplot$ ?  xrange range na.rm  iqr diff"' ?? bwex /+'@* xhi max)  xusr# $ par usr  :?@ = xpos pretty#  n@ +#0?- -#'?+0+' newpos8#0?-95#'?+0+'2 xpd  atvert switch 9#12 usr@#12 cxy@?陙 8#12 usr@#12 cxy@?陙  if !=<   boxplot at< boxwex, add T horizontalF xaxt n axis side  line?C: labels5 cex.axis? mgp @?2;  function(z, boxplot.side=1){ % xrange <- range(z,na.rm=TRUE) 1 iqr <- diff(quantile(xrange, c(.25,.75))) $ bwex <- diff(xrange)/(3*iqr) xhi <- max(z,na.rm=TRUE) ! xusr <- par()$usr[c(1:2)] & xpos=pretty(z[!is.na(z)], n=5) : z <- xusr[1]+(z-xrange[1])*diff(xusr)/diff(xrange) B newpos <- xusr[1]+(xpos-xrange[1])*diff(xusr)/diff(xrange)  par(xpd=TRUE) E atvert <- switch(boxplot.side, par()$usr[3]-par()$cxy[2]*0.8, ? "", par()$usr[4]+par()$cxy[2]*0.8, "")  if(atvert!=""){ M boxplot(z, at=atvert, boxwex=bwex, add=T, horizontal=T, xaxt="n") - axis(side=boxplot.side, line=1.5, I at=newpos, labels=xpos, cex.axis=0.75, mgp=c(2, 0.5, 0)) }  par(xpd=FALSE)  }@ >=?-$@O?-$ tmpind > probs9? <R7 prod unlist n.all% n.na sum  nhalf %/%%@ n2@Y n.one% plo-3YY phi9?-3YY quiles1] quiles2^@ ==  intervals #_3@Y8#_?-9#_8Y?#_?3?9Y?Y#`3@Y9#`?-9#`8Y?#`?39Y??Y#]9? sapply#_9? x-X <=c)F$ -function(x, z)sum(z<=x, na.rm=T)/length.na(z)#^9?b#`9?c-Xdc)F$ -function(x, z)sum(z<=x, na.rm=T)/length.na(z)@S8?  quiles _` frac ]^ colpal #3?Y #FFFFFF#389\Y?\ midbreak  gh e-3\\f ]#^9? dups duplicatede@ anyi  cats seq along#e9? filledcats#li cutcats as.integer cut#ei include.lowest  fullm#optqres \%g nrects%e@k   nacat #t t8/ unique#t t?g g v @ &A% as.vector7 is.null names  y#tPt rep 7#tq{||#tP @xA%y7z{  stop ] Error: Length of vector is different from total number of spots and vector has no row.name. 1 ngrid.c1 ngrid.r1 nspot.c1 nspot.r fullt image3? ncol3? nrow t axes  xlab  ylab  colg box abline v839??? h83?9??@ %in%  ?@& @ @@  chw#12 cxy? barwid?@a@  x099#12 usr? xcutpos9?ٙ xquilepos88?ᙙ srt@V 8#12>@88?ٙ9?ٙ9@V yvals2#m from#12 usr@ to#12 usr@%888[h@v?9888[h@v? eps2+#3?@@v  nlast% nclast%g rect#88##g;F text8?8#? NA; #939?g#g9@h 88g;F #?8 paste signife@;  cex?陙#? (0%); ? fracs#f9 ?%f#9? ( round@Y@ ) sep ; ?8#% (100%); ? #3?Y88#3?Y#g3?Y;F#38Y@8@Y?88#38Y@8@Y?#g38Y@8@Y?;F#3?8Y?_@; ?陙#3@8Y? (#]9?@Y@ ) ; ?#? (0%); ? #38Y@8@Y?8#8@Y?`@; ?陙#38Y@8@Y? (#^9%^@Y@ ) ; ?8#8@Y? (100%); ? invisible