[英]WordCloud of transaction activities in R
I am trying to generate a wordcloud from some transaction activities in order to show where people spend the most money. 我试图通过一些交易活动生成一个词云,以显示人们在哪里花了最多的钱。 The transaction activities look like the following:
事务活动如下所示:
Description Amount
Albertson 20
Albertson 30
Albertson 35
CVS 10
CVS 40
Walmart 15
Walmart 44
...
I can generate wordcloud easily by Description's frequency. 我可以通过Description的频率轻松生成wordcloud。 But how can I get wordcloud which sorted by sum(amount) of each category?
但是,如何获得按每个类别的总和(金额)排序的wordcloud? Thanks!
谢谢!
BTW here is my code 顺便说一句这是我的代码
require(tm)
require(wordcloud)
require(RColorBrewer)
data_corpus <- Corpus(VectorSource(data))
data_corpus <- tm_map(data_corpus, content_transformer(tolower), mc.cores=1)
data_corpus <- tm_map(data_corpus, removePunctuation, mc.cores=1)
data_corpus <- tm_map(data_corpus, function(x)removeWords(x,stopwords()), mc.cores=1)
data_corpus <- tm_map(data_corpus, removeNumbers, mc.cores=1)
pal2 <- brewer.pal(8,"Dark2")
png("25-34.png", width=1280,height=800)
wordcloud(data_corpus, scale=c(6,.2),min.freq=50,max.words=Inf, random.order=FALSE, rot.per=.15, colors=pal2)
dev.off()
I loaded your mini table into a dataframe called data. 我将您的迷你表加载到一个名为data的数据框中。 Then ran the following code:
然后运行以下代码:
require(wordcloud)
require(RColorBrewer)
library(dplyr)
# group by Description and sum the Amounts
data <- data %>% group_by(Description) %>% summarise(Amount = sum(Amount))
pal2 <- brewer.pal(8,"Dark2")
wordcloud(data$Description, freq = data$Amount, scale=c(6,.2),min.freq=50,max.words=Inf, random.order=FALSE, rot.per=.15, colors=pal2)
No need for the tm package. 不需要tm软件包。 Just specify your description in the words section and the Amount in the frequency section.
只需在文字部分指定您的描述,在频率部分指定金额。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.