Rendering Word Clouds

Zhenxing Cheng

2019-08-06

Introduction

The htmlwidgets package is very interesting and powerful. All the time, I want to write my own html widgets, but I failed. This is my third try, finally I success! As I first try of using htmlwidgets, I hope you will tolerate some of the flaws of this R package, and I will improve it in the future. Next, let’s use hwordcloud!

First, you can install it from github:

devtools::install_github('czxa/hwordcloud')
# or just use git
devtools::install_git("https://github.com/czxa/hwordcloud.git")

Also, I made a shiny application example for this package:

dir <- system.file("examples", "hwordcloud", package = "hwordcloud")
setwd(dir)
shiny::shinyAppDir(".")

Enjoy your use!

Get Started

A Basic example

We can use wordcloud2’s datesets to demonstrate:

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyHighcharts.com

Theme Parameter

I hate complex codes, so I built some themes in this package. Just change theme parameter, you can render wordcloud in different apperance.

darkgreen

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyHighcharts.com

darkblue

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyHighcharts.com

avocado

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyHighcharts.com

darkunica

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyHighcharts.com

gray

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyHighcharts.com

gridlight

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyHighcharts.com

grid

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyHighcharts.com

sandsignika

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyHighcharts.com

sunset

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyHighcharts.com

Other Parameter

Title and subtitle are also can be customized.

A complete example:

Created with Highcharts 7.0.3oilsaidpricesopecmlnthelastbpddlrscrudemarketreutersaudiwillonebarrelkuwaitnewofficialpctpricebarrelsgovernmentproductionsheikhindustrymeetingministerworldalsobillionfuturesmonthoutputpetroleumquotasourcesaccordanalystsbutgroupgulfjanuarymarketsreporttodaydecemberdemandeconomiceconomyWord Cloudczxa.topHighcharts.com

Using hwordcloud within RMarkdown documents

Benefit from htmlwidgets, you can use hwordcloud() function in R Markdown document. For example, you can create a github document and code following codes in it, save it as a .Rmd documents, then knit it, you will find a word cloud embedded in it.

Using hwordcloud within Shiny applications

Here is a very simple shiny example: