我正在使用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))
任何帮助解决这个问题都将不胜感激!
opts_chunk$set(tidy = FALSE)
的意思是关闭代码块的自动整理功能。 - kohske