Alison Meeth
Alison Meeth

Reputation: 95

Getting an error when trying to knit my document using Rmarkdown

I have this code:

```{r,echo=TRUE}
lg <- function(x, a = 1, b = 1){
  exp(a+b*x) / (1+exp(a+b*x))
}
```

```{r,echo=TRUE}
for (b in c(1:5)){
  curve(expr = lg(x, 1, b), from = -5, to = 5, n = 100, add= TRUE, col = b)
}
```

But when I go to knit the document it gets stuck on line 89 which is the one that starts with for... I get an error that says,

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

Calls: <Anonymous> ... eval -> curve -> lines -> lines.default -> plot.xy

I need to run these as separate chunks so that the graphs are separate but I'm not sure how to fix this error so I can knit the document.

Upvotes: 0

Views: 197

Answers (1)

user14692575
user14692575

Reputation:

Modifying this might help you:

lg <- function(x, a = 1, b = 1){
  exp(a+b*x) / (1+exp(a+b*x))
}
plot(NA, xlim = c(-5, 5), ylim = c(0, 1))
for (b in c(1:5)){
  curve(expr = lg(x, 1, b), from = -5, to = 5, n = 100, add= TRUE, col = b)
}

Upvotes: 1

Related Questions