1
```{r scatterplots, collapse=TRUE, results= 'hold'}
p1 <- ggplot(x, aes(y=f.ecdf, x=P2))+geom_point()+theme_bw()
p2 <- ggplot(x, aes(y=f.ecdf, x=P2))+geom_point()+theme_bw()
p3 <- ggplot(x, aes(y=f.ecdf, x=G1))+geom_point()+theme_bw()
p4 <- ggplot(x, aes(y=f.ecdf, x=G2))+geom_point()+theme_bw()
p5 <- ggplot(x, aes(y=f.ecdf, x=P2))+geom_point()+theme_bw()
p6 <- ggplot(x, aes(y=f.ecdf, x=P2))+geom_point()+theme_bw()
p7 <- ggplot(x, aes(y=f.ecdf, x=G1))+geom_point()+theme_bw()
p8 <- ggplot(x, aes(y=f.ecdf, x=G2))+geom_point()+theme_bw()

grid.arrange(
  p1, p2, p3, p4,
  ncol = 2
)

 grid.arrange(
   p5, p6, p7, p8,
   ncol = 2
)
```

But in preview the code chunks are being evaluated after splitting.

How can I stop this from happening. Basically, I want all plots to flow interrupted.

What other information can I provide to diagnose this?

enter image description here

maximusdooku
  • 5,242
  • 10
  • 54
  • 94

1 Answers1

0

Looks like there's a known issue of R notebooks ignoring chunk options: https://github.com/rstudio/rmarkdown/issues/1077, so not sure if there's a straightforward solution atm.

One ad hoc fix, probably not ideal, but you can use curly brackets e.g.

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

```{r scatterplots, collapse=TRUE, results= 'hold'}
library(ggplot2)
library(gridExtra)
set.seed(12345)
x <- data.frame(f.ecdf=rnorm(10), P2=rnorm(10), G1=rnorm(10), G2=rnorm(10))

p1 <- ggplot(x, aes(y=f.ecdf, x=P2))+geom_point()+theme_bw()
p2 <- ggplot(x, aes(y=f.ecdf, x=P2))+geom_point()+theme_bw()
p3 <- ggplot(x, aes(y=f.ecdf, x=G1))+geom_point()+theme_bw()
p4 <- ggplot(x, aes(y=f.ecdf, x=G2))+geom_point()+theme_bw()
p5 <- ggplot(x, aes(y=f.ecdf, x=P2))+geom_point()+theme_bw()
p6 <- ggplot(x, aes(y=f.ecdf, x=P2))+geom_point()+theme_bw()
p7 <- ggplot(x, aes(y=f.ecdf, x=G1))+geom_point()+theme_bw()
p8 <- ggplot(x, aes(y=f.ecdf, x=G2))+geom_point()+theme_bw()

{grid.arrange(
  p1, p2, p3, p4,
  ncol = 2
)

grid.arrange(
  p5, p6, p7, p8,
  ncol = 2
)}

screenshot

Yue Jiang
  • 1,271
  • 10
  • 15