首页 > 解决方案 > Wordcloud2 R:跨 rstudio、savewidget 和 webshot 保存相同的图像

问题描述

我想将 Rstudio 中的 wordcloud2 视图保存为 html 和 PNG 文件。

我正在关注这篇文章中的答案,包括 wordcloud2、htmlwidgets 和 webshot 库:如何在 R 中保存 wordcloud

    library(wordcloud2)
    library(htmlwidgets)
    library(webshot)
    
    set.seed(1)
    plot <- wordcloud2(word, freq, size = 1,  minRotation = 0, 
                 maxRotation = 0, shuffle = FALSE, 
                 color = rainbow(nrow(word))
    print(plot)
    
    saveWidget(plot, "test.html", selfcontained = FALSE)
    webshot("test.html", "test.png", delay=15)

我面临的问题是,每个可视化在单词的位置方面都略有不同。有没有办法在保存步骤中避免这种随机性?

标签: rwordcloud2

解决方案


推荐阅读