2

I am trying to knit an Rmarkdown document which contains a rather large ggplot, that I have created using cowplot

This is how one might create such a plot:

library(DOSE)
library(cowplot)
library(enrichplot)
data(geneList)
de <- names(geneList)[abs(geneList) > 2]
edo <- enrichDGN(de)
p1 <- dotplot(edo, showCategory=30) + ggtitle("dotplot for ORA")
p2 <- dotplot(edo, showCategory=30) + ggtitle("dotplot for ORA")
p3 <- dotplot(edo, showCategory=30) + ggtitle("dotplot for ORA")

plot_grid(p1,p2,p3, ncol=3)

I have added the following parameters in the header of the code chunk of my markdown document:

{test echo=F, fig.height=8, fig.width=20, fig.show="hold", fig.align="center"}

When I run the code chunk in Rstudio, the resulting image is clear and perfectly readable. However, when I try to knit it to an html file, it comes out very blurred and barely readable.. Are there any parameters that I should use that I am missing? Increasing dpi did not help.

It would also be fine, if the image is wider than the text of the markdown document if that increases quality.

Any help is much appreciated!

Cheers!

Phil
  • 7,287
  • 3
  • 36
  • 66
nhaus
  • 786
  • 3
  • 13
  • 2
    How about adjusting the `fig.retina` parameter? [See here](http://zevross.com/blog/2017/06/19/tips-and-tricks-for-working-with-images-and-figures-in-r-markdown-documents/#the-fig.retina-argument-is-a-resolution-multiplier) for a discussion. – DaveArmstrong Jan 18 '22 at 18:24
  • 1
    When I render the RMD in Viewer it does look a bit blurry. However, when I open it in my browser, even zoomed to 500% it's really clear. Have you looked at it in the browser yet? – Kat Jan 18 '22 at 18:59
  • @DaveArmstrong changing the `fig.retina` parameter doesn't help unfortunately. – nhaus Jan 18 '22 at 21:04
  • @Kat2 Honestly, if I open the HTML in chrome and zoom, the plot doesnt get closer at all. I dont know why this happens. This is how it looks at 500% zoom: https://pasteboard.co/olxnDN3kK0f3.png – nhaus Jan 18 '22 at 21:07
  • I had the same issue. Setting `fig.retina=3` solved things for me. – louish Jan 23 '23 at 10:07

1 Answers1

0

if you know you want to knit to html, then you should be using out.width and out.height using pixels or percentages to specify dimensions. The fig.width and fig.height are used more so for R-generated images. The out.width and out.height can be for both R-generated and HTML. Nice explanation here: https://www.zevross.com/blog/2017/06/19/tips-and-tricks-for-working-with-images-and-figures-in-r-markdown-documents/

Jonni
  • 804
  • 5
  • 16