RMarkdown Coding Error

Hi all, I have the following code in RMarkdown

mu1 = 5
mu2 = -2.7
sigma1sq = 0.8
sigma2sq = 0.23
y = seq(-2, 6, by = 0.001)
N = length(y)
dY = rep(-99, N)
for(i in 1:N){
	X2.samp = rnorm(N, mu2, sqrt(sigma2sq))
	dY[i] = mean(dnorm(y[i]-X2.samp, mu1, sqrt(sigma1sq)))
}
lines(y, dY, col = "blue", lty = 5)

And it gives me the error

Error in plot.xy(xy.coords(x, y), type = type, ...) : 
  plot.new has not been called yet

Could anyone give me some hints? Thank you in advance!

Lines is an add-on after some other plot object, such as plot(). More flexibility that way with ggplot

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.