用R语言来做词云

创建包

devtools::install_github("lchiffon/wordcloud2")

示例

library(wordcloud2)
wordcloud2(demoFreq, size = 1,shape = 'star')
用R语言来做词云_第1张图片
image
wordcloud2(demoFreq, size = 2, minRotation = -pi/2, maxRotation = -pi/2)
用R语言来做词云_第2张图片
image
wordcloud2(demoFreq, size = 2, minRotation = -pi/6, maxRotation = -pi/6,
  rotateRatio = 1)
用R语言来做词云_第3张图片
image

中文版本

## Sys.setlocale("LC_CTYPE","eng")
wordcloud2(demoFreqC, size = 2, fontFamily = "微软雅黑",
           color = "random-light", backgroundColor = "grey")
用R语言来做词云_第4张图片
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.

用R语言来做词云_第5张图片
image

发布于 2019-09-11

你可能感兴趣的:(用R语言来做词云)