# must use results = "asis"

pacman::p_load(tidyverse)

for (spec in unique(iris$Species)) {
  cat("# ", spec, "\n\n")
  
  # ggplot for that species
  out <- ggplot(iris %>% filter(Species == spec), 
                aes(x = Sepal.Length, y = Sepal.Width)) +
    geom_point()
  
  # must explicitly print plot objects when in for loops
  print(out)
  
  # often must explicitly use line breaks
  cat(".\n\n")
  
  # text
  cat("This is a paragraph about ", spec, ".\n\n")
  
}

setosa

.

This is a paragraph about setosa .

versicolor

.

This is a paragraph about versicolor .

virginica

.

This is a paragraph about virginica .