Since I launched R2D3 around a year ago I’ve slowly been adding functionality to the package. I thought I’d post a quick update to highlight some of the latest additions, including; Venn Diagrams, Word Clouds, and a Cross Tab Heatmap.
Firstly the Venn Diagram. I took the D3 format from the work done by Ben Frederickson here.
To produce the diagram it follows the standard process I created for R2D3. Firstly create the json with the data. In this case, call the jsonOverlaps() function, on the browsers data that comes with the package. This data lists out people (an item variable) and browser (the group it belongs to). Items need to belong to more than one group for a Venn to have an overlap. You can specify the levels of overlap you want to consider. Then call the D3 function, D3Venn(), specifying the json data object and the output location for the file containing the D3 visualisation
JSON<-jsonOverlaps(browsers, overlaps = 4)
Here you can see the results of the made up data showing overlap in use of web browsers.
Next the Cross Tab Heat Map. In my role I’m regularly asked to compare two categorical groups. Often two different segmentations. The usual starting point is a cross tab of the two segmentations, with row percentages and column percentages. I’ve turned this into a standard D3 output which shows the total frequencies, the row percentages and column percentages in a heat map style. I based it around this D3 example
The input data here is a data frame containing the two categorical groups. The jsonXtab function calculates the frequencies and row and column percentages and formats it to json. Then D3Xtabheat converts it to the output
Here are the results. The drop down menu allows you to switch between frequencies, column percentages, and row percentages.
Lastly the word cloud. These visually represent frequencies of words in a document. I used this d3 word cloud implementation.
The data here is two vectors one containing the unique words and one the frequency. It is also possible to provide just a list of words without the frequency, and it will calculate the frequency from the word list. The function jsonwordcloud() forms the json object and then D3WordCloud() creates the D3 output.
words=c("big", "data", "machine", "learning", "wordcloud", "R", "d3js", "algorithm", "analytics", "science", "API")
freq=c(50, 50, 30, 30, 100, 10, 10, 10, 5, 5, 5 )
Here are the results. Not the most exciting word cloud, but you get the idea.
You can download and install the R2D3 package from my github using the devtools package and the install_github() function.