从R中的数据框创建wordcloud [英] Create wordcloud from a data frame in R

查看:147
本文介绍了从R中的数据框创建wordcloud的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个示例数据框.我尝试从项目"列中创建一个wordcloud.

I made a sample data frame. I try to make a wordcloud from the Projects column.

Hours<-c(2,3,4,2,1,1,3)
Project<-c("a","b","b","a","c","c","c")
Period<-c("2014-11-22","2014-11-23","2014-11-24","2014-11-22", "2014-11-23", "2014-11-23", "2014-11-24")
cd=data.frame(Project,Hours,Period)

这是我的代码:

cd$Project<-as.character(cd$Project)
wordcloud(cd$Project,min.freq=1)

但出现以下错误:

Error in strwidth(words[i], cex = size[i], ...) : invalid 'cex' value
In addition: Warning messages:
1: In max(freq) : no non-missing arguments to max; returning -Inf
2: In max(freq) : no non-missing arguments to max; returning -Inf

我在做什么错了?

推荐答案

我认为您缺少freq参数.您想要创建一列,以指示每个项目发生的频率.因此,我使用dplyr包中的count转换了数据.

I think you are missing the freq argument. You want to create a column indicating how often each project happened. I, therefore, transformed your data using count in the dplyr package.

library(dplyr)
library(wordcloud)

cd <- data.frame(Hours = c(2,3,4,2,1,1,3),
                 Project = c("a","b","b","a","c","c","c"),             
                 Period = c("2014-11-22","2014-11-23","2014-11-24",
                            "2014-11-22", "2014-11-23", "2014-11-23",
                            "2014-11-24"),
                 stringsAsFactors = FALSE)

cd2 <- count(cd, Project)

#  Project n
#1       a 2
#2       b 2
#3       c 3

wordcloud(words = cd2$Project, freq = cd2$n, min.freq = 1)

这篇关于从R中的数据框创建wordcloud的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆