Is it possible to create a Word Cloud with highcha

2019-08-23 05:23发布

I tried it with the following code, but somehow it didn't work for me:

x4 is a dataframe, n1 a character string, and n2 the number of counts per word.

hchart(x4 ,"wordcloud", hcaes(name = "n1", weight = "n2"))

1条回答
地球回转人心会变
2楼-- · 2019-08-23 05:27

There is a function for word cloud in highcharter, follow this code

data(reuters, package = "kernlab")



text = paste(
reuters[[1]])

textcld <- text %>% 
map(str_to_lower) %>% 
reduce(str_c) %>% 
str_split("\\s+") %>% 
unlist() %>% 
data_frame(word = .) %>% 
count(word, sort = TRUE) %>% 
anti_join(tidytext::stop_words)

hchart(textcld, "wordcloud", hcaes(name = word, weight = log(n)))

And should get something like the image below: enter image description here

查看更多
登录 后发表回答