title: Plot() will save to pdf() but the file is corrupted and there doesn't seem to be actual data written to it
body: <p>I am currently using library(methylKit) to analyze methylation data and as part of this process I am performing hierarchical clustering and PCA to visualize my data. I would like to export the plots for both, however when I try to save the plots using pdf() the file is created, but the file is only ~380 bytes and it cannot be opened by Preview in Mac. My code is as follows:</p>
  
  <p>For hierarchical clustering:</p>
  
  <pre><code>clustermap1 &lt;- clusterSamples(meth,dist="correlation",method="ward",plot=TRUE)
  pdf(file="ClusterMapCorrWard.pdf")
  plot(clustermap1)
  dev.off()
  </code></pre>
  
  <p>For PCA Screeplot</p>
  
  <pre><code>pdf(file="PPCAScreeplot.pdf")
  xx &lt;- barplot(project.pca.proportionvariances, 
                cex.names = 1,
                xlab = paste("Principal component (PC), 1-",length(project.pca$sdev)),
                ylab = "Proportion of variation (%)",
                main = "Scree plot", 
                ylim = c(0,20)
                )
  text(xx, y = project.pca.proportionvariances, 
           label = round(project.pca.proportionvariances,2), 
           pos = 3, 
           cex = 0.8)
  dev.off()
  </code></pre>
  
  <p>For PCA Pairs Plots</p>
  
  <pre><code>par(cex=1.0, cex.axis=0.8, cex.main=0.8)
  pdf(file="PCAPairsplot1-6.pdf")
  pairs(project.pca$x[,1:6], 
        col = "black", 
        main = "Principal components analysis bi-plot\nPCs 1-6", 
        pch = 16, 
        panel = function(x,...) { 
                text(project.pca$x, labels=minids, cex= 0.5, pos=3) 
                } 
        )
  dev.off()
  </code></pre>
  
  <p>For PCA Biplots</p>
  
  <pre><code>pdf(file="PCABiplotsPC1-2.pdf")
  plot(project.pca$x, 
       type = "n", 
       main = "Principal components analysis bi-plot", 
       xlab = paste("PC1, ", round(project.pca.proportionvariances[1], 2), "%"),
       ylab = paste("PC2, ", round(project.pca.proportionvariances[2], 2), "%"))
  points(project.pca$x, col="black", pch=16, cex=1)
  text(project.pca$x, labels=ids, cex= 0.7, pos=3)
  dev.off()
  </code></pre>
  
  <p>What I find confusing is that this code worked previously, and successfully outputted the appropriate plots. However, when I tried to use it on another dataset (of the same type and formatting), it stopped working and now won't work on the original data set either. Using png() is able to output the plot as well.</p>
  
  <p>So where have I gone wrong?</p>
  
  <p>Thanks</p>