用R语言来做词云

作者: 柳叶刀与小鼠标 | 来源:发表于2019-09-16 21:18 被阅读0次

    创建包

    devtools::install_github("lchiffon/wordcloud2")
    

    示例

    library(wordcloud2)
    wordcloud2(demoFreq, size = 1,shape = 'star')
    
    image
    wordcloud2(demoFreq, size = 2, minRotation = -pi/2, maxRotation = -pi/2)
    
    image
    wordcloud2(demoFreq, size = 2, minRotation = -pi/6, maxRotation = -pi/6,
      rotateRatio = 1)
    
    image

    中文版本

    ## Sys.setlocale("LC_CTYPE","eng")
    wordcloud2(demoFreqC, size = 2, fontFamily = "微软雅黑",
               color = "random-light", backgroundColor = "grey")
    
    image

    通过 R-shiny来绘制交互性图片

    library(shiny)
    library(wordcloud2)
    shinyApp(
      ui=shinyUI(fluidPage(
        #using default clicked word input id
        wordcloud2Output("my_wc", width = "50%", height = "400px"),
        #using custom clicked word input id
        wordcloud2Output("my_wc2", width = "50%", height = "400px"),
    
        verbatimTextOutput("print"),
        verbatimTextOutput("print2")
      )),
      server=shinyServer(function(input,output,session){
    
        figPath = system.file("examples/a.png",package = "wordcloud2")
    
        output$my_wc  = renderWordcloud2(wordcloud2(data = demoFreq, figPath = figPath, size = 0.4,color = "blue"))
        output$my_wc2 = renderWordcloud2(wordcloud2(demoFreq))
    
        #using default clicked word input id
        output$print  = renderPrint(input$my_wc_clicked_word)
        #using custom clicked word input id
        output$print2 = renderPrint(input$my_wc2_clicked_word)
      })
    )
    

    run the above code and click refresh, it will work.

    image

    发布于 2019-09-11

    相关文章

      网友评论

        本文标题:用R语言来做词云

        本文链接:https://www.haomeiwen.com/subject/cqbfuctx.html