Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R notebook generates a blank plot in addition to actual plot

I am using R notebook. This is my chunk:

```{r}
test = matrix(rnorm(200), 20, 10)
pheatmap::pheatmap(test)
```

I guess it's due to the way pheatmap generates the plot, but it actually generates a blank plot first. Thus, this is the output I see: enter image description here

How do I get rid of that first image? I see it in the RStudio output (screenshot above) and in the .nb.html file. If I knit to HTML, the blank plot is not there.

I tried different fig.keep options. They work when I knit to HTML, but they don't seem to have an effect in the .nb.html file. How can I get rid of it?

Update: This issue was fixed in pheatmap. It may still be applicable to other scenarios.

like image 645
burger Avatar asked Jul 11 '17 01:07

burger


1 Answers

This is weird. Try this:

```{r}
library(pheatmap)
p <- pheatmap(test, silent = TRUE)
plot(p$gtable)
```

It produces exactly what you describe. Now, split it into two chunks.

```{r}
library(pheatmap)
p <- pheatmap(test, silent = TRUE)
```

```{r}
plot(p$gtable)
```

It works! I have no idea why, though.

like image 51
Lyngbakr Avatar answered Sep 30 '22 20:09

Lyngbakr