Google Word Tree with R
A word tree depicts multiple parallel sequences of words. It could be used to show which words most often follow or precede a target word (e.g., "Cats are...") or to show a hierarchy of terms (e.g., a decision tree).
gvisWordTree( data, textvar = "", sizevar = "", stylevar = "", idvar = "", parentvar = "", options = list(), method = "implicit", chartid )
data |
|
textvar |
a string that refers to the column name in |
sizevar |
a string that refers to the column name in |
stylevar |
a string that refers to the column name in |
idvar |
(only when format is explicit) a string that refers to the
column name in |
parentvar |
(only when format is explicit) a string that refers to the
column name in |
options |
list of configuration options, see: https://developers.google.com/chart/interactive/docs/gallery/wordtree#Configuration_Options The parameters can be set via a named list. The parameters have to map those of the Google documentation.
For more details see the Google API documentation and the R examples below. |
method |
a string to say whether the word tree is either:
|
chartid |
character. If missing (default) a random chart id will be
generated based on chart type and |
gvisWordTree returns list
of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the
following components:
type
Google visualisation type
chartid
character id of the chart object. Unique chart ids are required to place several charts on the same page.
html
a list with the building blocks for a page
header
a character string of a html page header:
<html>...<body>
,
chart
a named character vector of the chart's building blocks:
jsHeader
Opening <script>
tag and
reference to Google's JavaScript library.
jsData
JavaScript function defining the input
data
as a JSON object.
jsDrawChart
JavaScript function combing the data with the visualisation API and user options.
jsDisplayChart
JavaScript function calling the handler to display the chart.
jsFooter
End tag </script>
.
jsChart
Call of the jsDisplayChart
function.
divChart
<div>
container to embed the chart
into the page.
caption
character string of a standard caption, including data name and chart id.
footer
character string of a html page footer:
</body>...</html>
, including the used R and googleVis version
and link to Google's Terms of Use.
The word tree chart may be undergoing substantial revisions in future Google Charts releases.
Ashley Baldry
Google Chart Tools API: https://developers.google.com/chart/interactive/docs/gallery/wordtree
## Please note that by default the googleVis plot command ## will open a browser window and requires Internet ## connection to display the visualisation. wt1 <- gvisWordTree(Cats, textvar = "Phrase") plot(wt1) Cats2 <- Cats Cats2$Phrase.style <- ifelse(Cats$Sentiment >= 7, "green", ifelse(Cats$Sentiment <= 3, "red", "black")) wt2 <- gvisWordTree(Cats2, textvar = "Phrase", stylevar = "Phrase.style", options = list(fontName = "Times-Roman", wordtree = "{word: 'cats'}", backgroundColor = "#cba")) plot(wt2) # Explicit word tree exp.data <- data.frame(id = as.numeric(0:9), label = letters[1:10], parent = c(-1, 0, 0, 0, 2, 2, 4, 6, 1, 7), size = c(10, 5, 3, 2, 2, 2, 1, 1, 5, 1), stringsAsFactors = FALSE) wt3 <- gvisWordTree(exp.data, idvar = "id", textvar = "label", parentvar = "parent", sizevar = "size", options = list(wordtree = "{format: 'explicit'}"), method = "explicit") plot(wt3)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.