Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"plot.new has not been called yet" error in rmarkdown (Rstudio 1.0.44)

Tags:

I am using a recent version of Rstudio with an iMac

Version 1.0.44 – © 2009-2016 RStudio, Inc. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/602.2.14 (KHTML, like Gecko)

And I noticed the notebook function for rmarkdown files. When generating plots, the usual "Plots window" is not used any more, and the plots are generated just below the code chunk.

And I have an error for the following code:

plot(seq(1,10,1)) abline(a=0,b=1) 

The error is showed below the code chunk :

Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) : plot.new has not been called yet 

However, when knitting the whole rmarkdown file, there is no error.

So I would like to know how to avoid the error:

  • by using another code
  • by using the "Plots window"
  • or another way.
like image 717
John Smith Avatar asked Dec 02 '16 18:12

John Smith


People also ask

How do you get plots on rmarkdown?

In RStudio, when you open a new RMarkdown file, in the editor pane, there is a cogwheel button / menu where you can choose "Chunk Output Inline". That should put the plots into the document.

What does plot new has not been called yet mean?

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.

What is plot new in R?

. plot.new() signals to R that a new plot is to be produced. This will open a new. graphics window if there is none open, otherwise an existing window is readied to hold the new plot.

What is rmarkdown in RStudio?

Workflow R Markdown is a format for writing reproducible, dynamic reports with R. Use it to. embed R code and results into slideshows, pdfs, html documents, Word files and more.


2 Answers

The following will work

{plot(seq(1,10,1))  abline(a=0,b=1)} 
like image 125
user7492565 Avatar answered Sep 21 '22 01:09

user7492565


In RStudio, there's a setting in Preferences -> R Markdown to "Show output inline for all R Markdown documents". To get rid of the error, make sure this is unchecked.

like image 32
Mike W Avatar answered Sep 21 '22 01:09

Mike W