我的 plot() 代码是否有问题导致它无法编织?
Is there a problem with my plot() code keeping it from knitting?
这是我的数据集 (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
下面的代码运行良好,直到我尝试编织它:
```{r}
lmod = nls(Mass ~ a + b*Age, data = dinodat, start = list(a = 1, b = 0.25))
summary(lmod)
plot(lmod)
confint(lmod)
```
这是第 15 行的错误,该行以“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
这是给你的 markdown(编织成 .pdf)。
我使用 ggplot2 库绘制了一个图。
你绝对应该研究这个包;你会有更多的可能性,用它制作的图表看起来真的很酷。
我还使用 flextable 库在漂亮的 table 中输出 data.frame (数据是随机写入的)。
---
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
```
和情节:
这是我的数据集 (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
下面的代码运行良好,直到我尝试编织它:
```{r}
lmod = nls(Mass ~ a + b*Age, data = dinodat, start = list(a = 1, b = 0.25))
summary(lmod)
plot(lmod)
confint(lmod)
```
这是第 15 行的错误,该行以“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
这是给你的 markdown(编织成 .pdf)。
我使用 ggplot2 库绘制了一个图。 你绝对应该研究这个包;你会有更多的可能性,用它制作的图表看起来真的很酷。
我还使用 flextable 库在漂亮的 table 中输出 data.frame (数据是随机写入的)。
---
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
```
和情节: