plot output of loop to pdf - produces empty page(s)

Viewed 284

I used pdf("file.pdf") and dev.off() several times to save plots in R, but now I encountered a very strange problem and I have no idea where it even comes from.

I have some example code for demonstration:

m <- matrix(rnorm(6),6,9)
data <- data.frame(m)
rownames(m)<- c("20180_T0105", "20180_T0104", "20180_T02808", "01804_T80485", "01808_T80438", "80385_T44248")
colnames(m) <- c(1:9)
K=9

pdf("OutlierScreen.pdf")
par(mfrow=c(2,round(K/2)))
for(c in 2:K) {
  print(plot(data[,1],data[,c],xlab="O-1", ylab=paste("O-",c,sep="")))
}
dev.off()

I did this on my Windows Computer with R Studio and it worked fine. Then I did this on my Linux Computer with R Studio (and additionally with R run at a cluster) at work (where I discovered the problem with original data) and it happened again:

The pdf file is generated, but empty apart from the axes! So in this example, the data points are missing.

What could be the source of this problem?? Could it be something with a package?

Also, related but not the main problem as I just tried to somehow fix the problem with this: I tried to plot the graphic in a list and then print it to a pdf, but the list remains empty..?:

plist <- list()
par(mfrow=c(2,round(K/2)))
for(c in 2:K) {
  p<- plot(data[,1],data[,c],xlab="O-1", ylab=paste("O-",c,sep=""))
  plist[[c]] <-p
}

Thanks for any hint, tip, suggestion!!

Added: Session Info R version 3.5.0 (2018-04-23) Platform: x86_64-suse-linux-gnu (64-bit) Running under: openSUSE Leap 15.0

Matrix products: default BLAS: /usr/lib64/R/lib/libRblas.so LAPACK: /usr/lib64/R/lib/libRlapack.so

locale: [1] LC_CTYPE=de_DE.UTF-8 LC_NUMERIC=C LC_TIME=de_DE.UTF-8 LC_COLLATE=de_DE.UTF-8 LC_MONETARY=de_DE.UTF-8
[6] LC_MESSAGES=de_DE.UTF-8 LC_PAPER=de_DE.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] compiler_3.5.0 tools_3.5.0

0 Answers
Related