我正在使用带有 R Markdown 的 knitr 包来创建 HTML 报告。使用“+”时,我在将代码放在单独的行上时遇到了一些麻烦。
例如,
```{r}
ggplot2(mydata, aes(x, y)) +
geom_point()
```
将返回以下 HTML 文档
ggplot2(mydata, aes(x, y)) + geom_point()
通常这很好,但是一旦我开始添加额外的行就会出现问题,我想将它们分开以使代码更容易理解。运行以下:
```{r}
ggplot2(mydata, aes(x, y)) +
geom_point() +
geom_line() +
opts(panel.background = theme_rect(fill = "lightsteelblue2"),
panel.border = theme_rect(col = "grey"),
panel.grid.major = theme_line(col = "grey90"),
axis.ticks = theme_blank(),
axis.text.x = theme_text (size = 14, vjust = 0),
axis.text.y = theme_text (size = 14, hjust = 1.3))
```
将导致所有代码在一行中出现,使其更难遵循:
ggplot2(mydata, aes(x, y)) + geom_point() + geom_line() + opts(panel.background = theme_rect(fill = "lightsteelblue2"), panel.border = theme_rect(col = "grey"), panel.grid.major = theme_line(col = "grey90"), axis.ticks = theme_blank(), axis.text.x = theme_text (size = 14, vjust = 0), axis.text.y = theme_text (size = 14, hjust = 1.3))
任何解决此问题的帮助将不胜感激!