Reputation: 1698
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:
Upvotes: 28
Views: 55002
Reputation: 932
This was happening to me because I was adding an invalid parameter to my plot. In my case I was trying to execute:
ggplot(df, aes(x=sales)) + geom_histogram() + title('Plot Title')
And should have been executing:
ggplot(df, aes(x=sales)) + geom_histogram() + ggtitle('Plot Title')
Notice that you must use ggtitle
, not title
.
Upvotes: 1
Reputation: 117
In jupyter with R kernel, you will see that error if run the code line by line, just as XR SC mentioned.
Upvotes: 2
Reputation: 97
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.
Upvotes: 8