Wordcloud2 : Is it possible to only show words that appear n times?

120 views Asked by At

I created a beautiful word cloud with wordcloud2 but I want to only show words that appears n times. How to do it ?

data <- read.table(text = 'my data', sep = ";")
dim(data)
library(tm)
documents <- Corpus(VectorSource(data$V2))
inspect(documents)

lapply(documents[1],as.character)
inspect(documents)

set.seed(1234)

tdm <- TermDocumentMatrix(documents)
m <- as.matrix(tdm)
v <- sort(rowSums(m),decreasing=TRUE)
d <- data.frame(word = names(v), freq = v)
d$word=rownames(d)

library("wordcloud2")
wordcloud2(d)
1

There are 1 answers

0
klaus On

Finally, I used :

d <- d[c(1:n), ]

if I want to keep the first n lines of data