Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in plot.new() when creating PDF in R

Tags:

r

pdf

dendrogram

When plotting a dendrogram in R, I get a funny error that I've never seen before.

Error in plot.new() : 
  cannot open file 'C:\Users\Sun\AppData\Local\Temp\RtmpKSRNuD\pdf12207aa37548', reason No such file or directory

I didn't have that error yesterday when plotting other dendrograms and saving it in PDF files .. Any idea what it means?

like image 830
madkitty Avatar asked May 28 '15 17:05

madkitty


People also ask

What does error in plot new () figure margins too large mean in R?

new() : figure margins too large. One error you may encounter in R is: Error in plot.new() : figure margins too large. This error occurs when the plot panel in RStudio is too small for the margins of the plot that you're attempting to create.

What does plot new mean in R?

This error occurs when you attempt to perform some action that requires a plot to already exist in R, yet a plot does not exist. The following examples show how to fix this error in practice.

How do you fix the margins in R?

You can adjust the size of the margins by specifying a margin parameter using the syntax par(mar = c(bottom, left, top, right)) , where the arguments bottom , left … are the size of the margins. The default value for mar is c(5.1, 4.1, 4.1, 2.1).

What does plot new has not been called yet in R mean?

The above error means plot is not being created yet hence abline function cannot be used to draw anything on the plot. Therefore, a plot needs to be created first to use abline function for creating a line or any other thing.


1 Answers

Related answer at Plot() error when using REngine.Rserve suggests sending a dev.close() call as a workaround for "not closing the device correctly last time" (specifically under Rserve).

Related answer at Cannot open file '', reason No such file or directory suggests using file.path as a alternative to paste for creating filenames with platform-independent path separators.

I'm having better luck with graphics.off(). The difference is that dev.close() closes the current device, graphics.off() closes all open devices. In my case, I'm writing a PDF inside a knitr Rmd called from an Rserve session, so I may have multiple open devices.

I'm also finding that there's a mysterious folder named (null).1001.1001 (it's on an Ubuntu box, logged in as uid 1001, gid 1001). The presence of this folder seems to help in my case.

like image 127
woodvi Avatar answered Sep 30 '22 05:09

woodvi