r - 如何在 r 中创建和打印 wordcloud
问题描述
不知道我错过了什么,但是当我运行这个 wordcloud 示例时,没有绘制任何内容并且 x = NULL。
图书馆都是可用的。
abc<-data.frame(X=LETTERS[1:26],x=sample(1:26))
x = wordcloud(abc$X,abc$x,scale = c(5,.5),min.freq = 2,colors = brewer.pal(10,"Paired"))
解决方案
您可以使用 quanteda 包。基于他们的文档的示例https://quanteda.io/reference/textplot_wordcloud.html
library(quanteda)
#convert readLines input to a token object
tok <- tokens(unlist(sample.lines))
#convert the token object to a frequency matrix
dfmat1 <- dfm(tok,
remove = stopwords("english"), #remove stopwords (if wanted)
remove_punct = TRUE, #remove punctuation (if wanted)
tolower = T, #(change all to lowercase (if wanted)
removeNumbers = TRUE) %>% #remove numbers (if wanted)
dfm_trim(min_termfreq = 4) #eliminate frequencies lower than 4 (if wanted)
# basic wordcloud
textplot_wordcloud(dfmat1)
# plot in colors with some additional options
textplot_wordcloud(dfmat1, rotation = 0.25,
color = rev(RColorBrewer::brewer.pal(10, "RdBu")))
# other display options
col <- sapply(seq(0.1, 1, 0.1), function(x) adjustcolor("#1F78B4", x))
textplot_wordcloud(dfmat1, adjust = 0.5, random_order = FALSE,
color = col, rotation = FALSE)
推荐阅读
- inheritance - Nestjs 覆盖基本服务方法
- javascript - 返回 json 名称自定义 utils nodejs
- python - 在没有 GPU 支持的 MacOS 上安装 cupy
- javascript - 将视频上传到 Instagram 时出现媒体 ID 不可用错误
- python - 从python中的txt文件读取表格
- c++ - 在 Linux 或 Mac 中是否有与 getprop/setprop 类似的命令?
- javascript - 如何消除价格零点?
- c - printf() 是否以字节顺序打印?
- c# - 赛马林。Forms App Shell 不同的弹出窗口
- android - 在jetpack compose中点击另一个组件时触发点击效果