1

I am trying to generate a report in R notebook where a large number of plots are generated. I am trying to use the H1 tag to have a nice table of content but whenever I run my code. I get the titles bunched up at the top and the graphs bunched up at the bottom instead of having a title followed by the graph.

I am using this old SO as template.

Here is a minimalistic reproduction:

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

---

```{r, results='hide'}
library(tidyverse)

dt <- as_tibble(iris)

dt %>% mutate(Species = as.character(Species)) %>% 
  group_by(Species) %>%
  nest() %>%  
  mutate(plot = map(data, ~ ggplot(data=.x) + geom_line(aes(y= Sepal.Length, x= Sepal.Width)))) ->Plots
```

```{r echo = FALSE, results='asis'}

for( i in 1:nrow(Plots)){
  dt <- Plots[i,]
  cat('\n#', dt[[1]], '\n')
  p <- dt[[3]]
  print(p)
  cat('\n')
}
```

This is my output

Any ideas?

Jrakru56
  • 1,211
  • 9
  • 16

0 Answers0