library(ReporteRs)library(NMF)
sessionInfo() #
# R version 3.2.2 (2015-08-14)# Platform: x86_64-apple-darwin14.5.0 (64-bit)# Running under: OS X 10.10.5 (Yosemite)# # locale:# [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8# # attached base packages:# [1] parallel stats graphics grDevices utils datasets methods base # # other attached packages:# [1] ReporteRs_0.8.3 ReporteRsjars_0.0.2 NMF_0.20.6 synchronicity_1.1.4# [5] bigmemory_4.5.8 bigmemory.sri_0.1.3 Biobase_2.28.0 BiocGenerics_0.14.0# [9] cluster_2.0.3 rngtools_1.2.4 pkgmaker_0.22 registry_0.3 # # loaded via a namespace (and not attached):# [1] Rcpp_0.12.1 magrittr_1.5 MASS_7.3-44 munsell_0.4.2 # [5] doParallel_1.0.10 colorspace_1.2-6 xtable_1.7-4 gridBase_0.4-7 # [9] foreach_1.4.3 stringr_1.0.0 plyr_1.8.3 tools_3.2.2 # [13] grid_3.2.2 gtable_0.1.2 iterators_1.0.8 digest_0.6.8 # [17] rJava_0.9-8 RColorBrewer_1.1-2 reshape2_1.4.1 ggplot2_1.0.1 # [21] codetools_0.2-14 stringi_1.0-1 scales_0.3.0 proto_0.3-10
# Generate random datan <- 50; p <- 20datax <- abs(rmatrix(n, p, rnorm, mean=4, sd=1))datax[1:10, seq(1, 10, 2)] <- datax[1:10, seq(1, 10, 2)] + 3datax[11:20, seq(2, 10, 2)] <- datax[11:20, seq(2, 10, 2)] + 2rownames(datax) <- paste("ROW", 1:n)colnames(datax) <- paste("COL", 1:p)
# Set up power point docdoc = pptx()doc = addSlide( doc, "Title and Content" )
# plotting both dendrograms (default) gives an errordoc = addPlot(doc = doc, fun=function(){aheatmap(datax)}, width=9.5, height=6, offx=0.2, offy = 0.1)
#java.lang.ArrayIndexOutOfBoundsException: 2147483647Error in vector.pptx.graphic(doc = doc, fun = fun, pointsize = pointsize, : # an error occured when executing plot function.
# not plotting the row dendrogram works finedoc = addPlot(doc = doc, fun=function(){aheatmap(datax, Rowv=FALSE)}, width=9.5, height=6, offx=0.2, offy = 0.1)
writeDoc(doc, "exampleaheatmap.pptx")
I think aheatmap just uses grid graphics, and I'm pretty sure in the past, I've been able to get this to work, but with the latest version of both packages, I cannot.
The issue is identified. It’s a serious one but there should be an available correction soon.
I will let you know as soon as it will be available.
export2office = function(file = "plot", type="PPT", scaling = 90, aspectr=NULL, vector.graphic = TRUE, pointsize=20) {
file=sub("^(.*)[.].*", "\\1", file)
if (type=="PPT"|type=="PPTX") {ext=".pptx";type="PPT"} else {ext=".docx";type="DOC"}
require(ReporteRs)
captureplot = function() {p = invisible(recordPlot())
return(p)}
p = captureplot()
plotsize = dev.size()
plotaspectr = plotsize[[1]]/plotsize[[2]]
if (!is.null(aspectr)) plotaspectr=aspectr
myplot=function(pl=p) print(pl)
if (type=="PPT") {doc = pptx();doc = addSlide(doc, slide.layout = "Blank");pagesize = dim(doc)$slide.dim} else {doc = docx();pagesize = dim(doc)$page-dim(doc)$margins[c(4,3)]}
pageaspectr = pagesize["width"]/pagesize["height"]
if (pageaspectr>plotaspectr) {xf=plotaspectr/pageaspectr;yf=1} else {xf=1;yf=pageaspectr/plotaspectr}
w = (scaling/100)*pagesize["width"]*xf;
h = (scaling/100)*pagesize["height"]*yf
if (type=="PPT") {doc = addPlot( doc, myplot, vector.graphic = vector.graphic, pointsize = pointsize,
offx = (pagesize["width"]-w)/2, offy = (pagesize["height"]-h)/2,
width = w, height = h) } else {doc = addPlot( doc, myplot, vector.graphic = vector.graphic, pointsize = pointsize,width = w, height = h)}
writeDoc( doc, paste0(file,ext) )
}
export2ppt = function(type="PPT", ...) export2office(type=type,...)
options(java.parameters = "-Xmx12000m")
library(ReporteRs)
library(ReporteRsjars)
pairs(test_2m,lower.panel=panel.smooth, upper.panel=panel.cor,diag.panel=panel.hist)
export2ppt(file="test_2m_lines.pptx")
test_1m<-head(test_2m,n=1000000)
pairs(test_1m,lower.panel=panel.smooth, upper.panel=panel.cor,diag.panel=panel.hist)
export2ppt(file="test_1m_lines.pptx")
# here are the functions
panel.cor <- function(x, y, digits=2, cex.cor)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- abs(cor(x, y))
txt <- format(c(r, 0.123456789), digits=digits)[1]
test <- cor.test(x,y)
Signif <- ifelse(round(test$p.value,3)<0.001,"p<0.001",paste("p=",round(test$p.value,3)))
text(0.5, 0.25, paste("r=",txt))
text(.5, .75, Signif)
}
panel.smooth<-function (x, y, col = "blue", bg = NA, pch = 18,
cex = 0.8, col.smooth = "red", span = 2/3, iter = 3, ...)
{
points(x, y, pch = pch, col = col, bg = bg, cex = cex)
ok <- is.finite(x) & is.finite(y)
if (any(ok))
lines(stats::lowess(x[ok], y[ok], f = span, iter = iter), col = col.smooth, ...)# lowess line
abline(stats::lm(x[ok]~y[ok]),col= "orange") # regression line
}
panel.hist <- function(x, ...)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(usr[1:2], 0, 1.5) )
h <- hist(x, plot = FALSE)
breaks <- h$breaks; nB <- length(breaks)
y <- h$counts; y <- y/max(y)
rect(breaks[-nB], 0, breaks[-1], y, col="cyan", ...)
}
export2office = function(file = "plot", type="PPT", scaling = 90, aspectr=NULL, vector.graphic = TRUE, pointsize=20) {
file=sub("^(.*)[.].*", "\\1", file)
if (type=="PPT"|type=="PPTX") {ext=".pptx";type="PPT"} else {ext=".docx";type="DOC"}
require(ReporteRs)
captureplot = function() {p = invisible(recordPlot())
return(p)}
p = captureplot()
plotsize = dev.size()
plotaspectr = plotsize[[1]]/plotsize[[2]]
if (!is.null(aspectr)) plotaspectr=aspectr
myplot=function(pl=p) print(pl)
if (type=="PPT") {doc = pptx();doc = addSlide(doc, slide.layout = "Blank");pagesize = dim(doc)$slide.dim} else {doc = docx();pagesize = dim(doc)$page-dim(doc)$margins[c(4,3)]}
pageaspectr = pagesize["width"]/pagesize["height"]
if (pageaspectr>plotaspectr) {xf=plotaspectr/pageaspectr;yf=1} else {xf=1;yf=pageaspectr/plotaspectr}
w = (scaling/100)*pagesize["width"]*xf;
h = (scaling/100)*pagesize["height"]*yf
if (type=="PPT") {doc = addPlot( doc, myplot, vector.graphic = vector.graphic, pointsize = pointsize,
offx = (pagesize["width"]-w)/2, offy = (pagesize["height"]-h)/2,
width = w, height = h) } else {doc = addPlot( doc, myplot, vector.graphic = vector.graphic, pointsize = pointsize,width = w, height = h)}
writeDoc( doc, paste0(file,ext) )
}
export2ppt = function(type="PPT", ...) export2office(type=type,...)