用这种格式的数据很容易得到一个词云。我不得不根据您在图像中显示的格式创建一个虚拟数据框(见下文),但代码只是:
library(wordcloud2)
wordcloud2(spamwordcountdf)
使用的数据
spamwordcountdf <- structure(list(word = c(
"Unsecured debt", "Enlargement", "Money",
"Valium", "Viagra", "Vicodin", "Weight loss", "Opportunity",
"Xanax", "Bank", "Warning", "Suspicious", "Act now", "Don't delay",
"Wonderful"), count = c(151062L, 109878L, 105425L, 103997L, 100761L,
90840L, 89645L, 83720L, 58852L, 54181L, 47605L, 44695L, 42336L,
38793L, 36867L)), row.names = c("41", "55", "7", "139", "15",
"276", "174", "24", "73", "141", "46", "228", "242", "78", "130"
), class = "data.frame")
spamwordcountdf
#> word count
#> 41 Unsecured debt 151062
#> 55 Enlargement 109878
#> 7 Money 105425
#> 139 Valium 103997
#> 15 Viagra 100761
#> 276 Vicodin 90840
#> 174 Weight loss 89645
#> 24 Opportunity 83720
#> 73 Xanax 58852
#> 141 Bank 54181
#> 46 Warning 47605
#> 228 Suspicious 44695
#> 242 Act now 42336
#> 78 Don't delay 38793
#> 130 Wonderful 36867
由reprex package (v2.0.1) 于 2022 年 5 月 22 日创建