Home > OS >  Is there a problem with my plot() code keeping it from knitting?
Is there a problem with my plot() code keeping it from knitting?

Time:10-28

Here is a sample of my dataset (dinodat):

Age Mass
0.5 0.1072476
0.5 0.1072476
0.5 0.0972
0.5 0.0972
1   0.1414944
1   0.1414944
2   0.9437184
2   0.6666948
3   2.21085
3   1.8432
4   3.6
4   3.7090836
5   6.0665724
5   5.1944292
6   9.4610592
6   8.4694932
7   8.85735
7   8.85735
8   16.17165
8   15.8793984
9   18.3184128
9   24.3045684
10  29.2341636
11  29.6726688

The bellow code runs fine until I try to knit it:

```{r}
lmod = nls(Mass ~ a   b*Age, data = dinodat, start = list(a = 1, b = 0.25))
summary(lmod)
plot(lmod)
confint(lmod)
```

And this is the error at line 15 which is the line that starts with "lmod =..." :

Error in xy.coords(x,y,xlabel,ylabel,log) : 'x' is a list, but does not have components 'x' and 'y' Calls: ... withVisible -> eval -> eval -> plot -> plot.default -> xy.coords Execution halted

CodePudding user response:

This is a markdown for you (knit to .pdf).

I made a plot with using ggplot2 library. You definetly should study this package; you will have more possibilites and graphs made with it look really cooler.

Also I used flextable library for making an output of data.frame in the nice table (data is randomly written).

---
title: "Dinos are forever"
output:
  pdf_document: default
---

## R Markdown

```{r setup, include = FALSE}
library(ggplot2)
library(flextable)

Age <-c(0.5, 0.5, 0.5, 1, 1, 2, 2, 3, 6, 4, 3, 1, 10)
Mass <-c(0.1072476, 0.1072476, 0.0972, 0.0972, 0.1414944, 1.8432, 3.7090836, 3.7090836, 9.4610592, 9.4610592, 8.4694932, 8.4694932, 24.3045684)
dinodat <- data.frame(Age, Mass)
lmod = nls(Mass ~ a   b*Age, data = dinodat, start = list(a = 1, b = 0.25))
Dinos <- flextable(dinodat)

Dinos_plot <- ggplot(dinodat, aes(x = Age, y = Mass))   
              geom_point()  
              geom_smooth(method = "nls",
              method.args = list(formula = y ~ a   b*x,
                       start = list(a = 1, b = 0.25)),
              se = F,
              colour = "green3")

```

A dataset `r Dinos`

\newpage
```{r}
summary(lmod)
confint(lmod)
```

\newpage
A dinos_plot
```{r pressure, echo=FALSE}
Dinos_plot
```

and the plot:

enter image description here

  • Related