2

我通过导入两个不同的数据集在 Rmarkdown 中成功创建了两个 wordcloud,但是在我将它编织到 html 后,一个 wordcloud 没有出现。有谁知道如何修理它?


输出:html_document

knitr::opts_chunk$set(echo=FALSE, warning=FALSE, message=FALSE)
library(wordcloud2)
library(here)
library(rio)

词云 1

s1 <- import(here("data", "set1.xlsx"))
wordcloud2(s1, color = "random-light", backgroundColor = "dark")

词云 2

s2 <- import(here("data", "set2.xlsx"))
wordcloud2(s2, color = "random-light", backgroundColor = "dark")
4

1 回答 1

0

这是一个完全可重现的工作示例,它将结果写入图像文件然后查看它们。我曾经dput(head(s1))获取示例数据。注释掉您的环境。

---
title: "WordCloud_Trial"
output: html_document
---

```{r global_options, include=FALSE}
knitr::opts_chunk$set(echo=FALSE, warning=FALSE, message=FALSE)
```

```{r}
library(wordcloud2)
library(here)
library(rio)
library(webshot)
library(htmlwidgets)
```

## WordCloud 1
```{r echo=FALSE, message=FALSE, include=F}
#s1 <- import(here("data", "set1.xlsx"))
s1 <- structure(list(Type = c("provide", "include", "develop", "support", 
"create", "suggest"), `Token Frequency` = c(1218, 1095, 1088, 
1078, 1005, 988)), row.names = c(NA, 6L), class = "data.frame")
w1 <- wordcloud2(s1, color = "random-light", backgroundColor = "dark")
saveWidget(w1, '1.html', selfcontained = F)
webshot('1.html', '1.png', vwidth=700,vheight=500, delay = 5)
```
![](1.png)

## WordCloud 2
```{r echo=FALSE, message=FALSE, include=F}
#s2 <- import(here("data", "set2.xlsx")) 
s2 <- structure(list(Type = c("decrease", "cope", "accommodate", "confirm", 
"reinforce", "advance"), `Token Frequency` = c(251, 240, 232, 
229, 228, 227)), row.names = c(NA, 6L), class = "data.frame")
w2 = wordcloud2(s2, color = "random-light", backgroundColor = "dark")
saveWidget(w2, '2.html', selfcontained = F)
webshot('2.html', '2.png', vwidth=700,vheight=500, delay = 5)
```
![](2.png)
于 2019-12-22T22:37:50.460 回答