9

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.

burger
  • 5,683
  • 9
  • 40
  • 63

1 Answers1

2

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.

Dan
  • 11,370
  • 4
  • 43
  • 68
  • That works for me too. It's actually a slightly different output, though. For example, I get a gray background with `plot(p$gtable)`. – burger Jul 24 '17 at 14:53
  • 1
    @burger You can get white background by executing `grid.draw(p$gtable)` instead of `plot(p$gtable)`. – tuomastik Aug 25 '17 at 11:31