1

I would like to create a Rnotebook that contains for each group in my data:

  • A subsection header with the group name
  • A plot containing the data for that group. (obs the alternative of adding the group name to the title of the plot does not let me search the document afterward)

The code below (taken from the marked "answer" from a similar 2017 question) sort of does that, but does not produce the desired output because all the titles appear first, then all the plots. I want the intertwined so I can search by group name (I have 500 groups in my case, each plot is used to eyeball problems in the data)

---
title: "R Notebook"
output: html_notebook
---


```{r echo = FALSE, results ='asis'}
library(ggplot2)
for(Species in levels(iris$Species)){
  cat('\n#', Species, '\n')
  p <- ggplot(iris[iris$Species == Species,], aes(x = Sepal.Length, y = Sepal.Width)) +
    geom_point()
  print(p)
  cat('\n')
}

```
LucasMation
  • 2,408
  • 2
  • 22
  • 45

0 Answers0