Description Usage Arguments Value Examples
A simple grob for the word cloud
1 2 3 4 |
text |
A vector of words. |
fontsize |
The corresponding font size. With the frequency of the words known, |
line_space |
Space between lines. The value can be a |
word_space |
Space between words. The value can be a |
max_width |
The maximal width of the viewport to put the word cloud. The value can be a |
col |
Colors for the words. The value can be a vector, in numeric or character, which should have the same length as |
test |
Internally used. It basically adds borders to the words and the viewport. |
A grob
object. The width and height of the grob can be get by grobWidth
and grobHeight
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # very old R versions do not have strrep() function
if(!exists("strrep")) {
strrep = function(x, i) paste(rep(x, i), collapse = "")
}
words = sapply(1:30, function(x) strrep(sample(letters, 1), sample(3:10, 1)))
require(grid)
gb = word_cloud_grob(words, fontsize = runif(30, min = 5, max = 30),
max_width = 100)
grid.newpage(); grid.draw(gb)
# color as a single scalar
gb = word_cloud_grob(words, fontsize = runif(30, min = 5, max = 30),
max_width = 100, col = 1)
grid.newpage(); grid.draw(gb)
# color as a vector
gb = word_cloud_grob(words, fontsize = runif(30, min = 5, max = 30),
max_width = 100, col = 1:30)
grid.newpage(); grid.draw(gb)
# color as a function
require(circlize)
col_fun = colorRamp2(c(5, 17, 30), c("blue", "black", "red"))
gb = word_cloud_grob(words, fontsize = runif(30, min = 5, max = 30),
max_width = 100, col = function(fs) col_fun(fs))
grid.newpage(); grid.draw(gb)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.