Adding a line break to code blocks in R Markdown -
i using knitr package r markdown create html report. having trouble keeping code on separate lines when using '+'.
for example,
```{r} ggplot2(mydata, aes(x, y)) + geom_point() ```
will return following the html document
ggplot2(mydata, aes(x, y)) + geom_point()
normally fine, problem arises once start adding additional lines, want keep separate make code easier follow. running following:
```{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)) ```
will result in code coming out in 1 line, making harder follow:
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))
any in solving appreciated!
try chunk option tidy = false
:
```{r tidy=false} 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)) ```
Comments
Post a Comment