Is there any way to show a wordcloud2 in Rmarkdown as a PDF or Word file?

前端 未结 1 1311
长情又很酷
长情又很酷 2021-01-07 03:15

I\'m trying to show a wordcloud2 wordcloud, but it only works in an html-knitted Rmd file. This works:

---
title: \"Untitled\"
output: html_document
---

``         


        
相关标签:
1条回答
  • 2021-01-07 03:34

    One way to do it, as I said, is to save as an image and load it in .Rmd. Not too bad actually:

    ---
    title: "Untitled"
    output: pdf_document
    ---
    
    ```{r wordcloud}
    library(wordcloud2)
    library(webshot)
    library(htmlwidgets)
    my_graph <- wordcloud2(demoFreq, size = 1.5)
    saveWidget(my_graph, "tmp.html", selfcontained = F)
    webshot("tmp.html", "wc1.png", delay = 5, vwidth = 2000, vheight = 2000)
    ```
    ![wordcloud](wc1.png)
    

    The delay argument needs to be big enough to let the html fully render; if you watch a wordcloud2 generate, it takes a few seconds. 5 seconds seems enough for this, but you may have to increase it for bigger/more complex wordclouds, or if your computer is slow.

    0 讨论(0)
提交回复
热议问题