R闪亮的双字wordcloud

时间:2019-01-09 11:18:38

标签: r shiny word-cloud

我正在尝试在R Shiny中制作双字母组wordcloud。但是它的抛出错误。 请在下面我的server.R代码中找到建议我的地方。 我可以使一个单词云,但不能使二字或三字组。

shinyServer(function(input, output) {

    wc_data = reactive({

input$update

isolate({

  withProgress({
    setProgress(message = "Processing Corpus...")
    wc_file = input$wc
    if(!is.null(wc_file)){
      wc_text = readLines(wc_file$datapath)
    }
    else
    {
      wc_text = "A wordcloud is an image made of words that together resemble a cloudy shape."
    }
    wc_corpus = Corpus(VectorSource(wc_text))
    wc_corpus_clean = tm_map(wc_corpus,tolower)
    wc_corpus_clean = tm_map(wc_corpus_clean, removePunctuation)
    wc_corpus_clean = tm_map(wc_corpus_clean, removeNumbers)
    wc_corpus_clean = tm_map(wc_corpus_clean, removeWords, stopwords("English"))
    wc_corpus_clean = tm_map(wc_corpus_clean, removeWords, c("since", "for", "this", "like", "that", "our", "united states", "will", "america", "s", "ve", "'"))
    wc_corpus_clean = tm_map(wc_corpus_clean, stripWhitespace)

    bigrams = textcnt(wc_corpus_clean, n = 2, method = "string")
    bigrams = bigrams[order(bigrams, decreasing = TRUE)]
    test_data = data.frame(bigrams = names(bigrams), freq = bigrams)
      })
    })
 })

  wordcloud_rep = repeatable(wordcloud)

  output$wcplot = renderPlot({
    withProgress({
      setProgress(message = "Creating WordCloud....")
      wc_corpus_clean = wc_data()
      wordcloud(wc_corpus_clean, min.freq = 5, scale = c(2,0.3), max.words  = 200, colors = brewer.pal(8,"Dark2"),rot.per = 0.45,random.order = FALSE)
   })
  })

})

0 个答案:

没有答案