d3wordcloud: D3 JavaScript Wordcloud Graphs from R

Description Usage Arguments Examples

View source: R/d3wordcloud.R

Description

Create D3 JavaScript wordcloud

Usage

1
2
3
4
d3wordcloud(words, freqs, colors = NULL, font = "Open Sans", padding = 1,
  rotate.min = -30, rotate.max = 30, size.scale = "linear",
  color.scale = "linear", spiral = "archimedean", tooltip = FALSE,
  label = NULL, rangesizefont = c(10, 90), width = NULL, height = NULL)

Arguments

words

The words

freqs

Their frequencies

colors

The color for wordcloud, if the length of words, and colors are the same, then each word will have its own color, in other case a grandien between the colors is generated (the order is important here).

font

The font to use in thw the word cloud. Default value is 'Open Sans'.

padding

The separation between words. Default value is '0'.

rotate.min

Minimum angle for (random) rotation. Default value is '-30'.

rotate.max

Maximum angle for (random) rotation. Default value is '30'.

size.scale

The scale to use for scale the words sizes ('freqs'). Options are 'linear', 'sqrt' and 'log'. Default value is 'linear'.

color.scale

The scale to use for scale the colors according to sizes ('freqs'). Options are 'linear', 'sqrt' and 'log'. Default value is 'linear'.

spiral

The way to construct the wordcloud. Options are 'archimedean' and 'rectangular'. Default value is 'archimedean'.

tooltip

Boolean indicating if the cursor is over the text show a tooltip with the size

label

character vector of alternate text to use in tooltips (must match length of unique words).

rangesizefont

A 2 length numeric vector indicating the size of text.

width

widget's width

height

widget's height

Examples

 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
## Not run: 
library("tm")
library("dplyr")
library("viridis")

data(crude)
crude <- tm_map(crude, removePunctuation)
crude <- tm_map(crude, function(x){ removeWords(x, stopwords()) })
tdm <- TermDocumentMatrix(crude)
m <- as.matrix(tdm)
v <- sort(rowSums(m), decreasing = TRUE)
d <- data.frame(word = names(v), freq = v)
d <- d %>% tbl_df()
d <- d %>% arrange(desc(freq))
d <- d %>% head(100)

words <- d$word
freqs <- d$freq

set.seed(123)
colors <- replicate(length(words), {
  paste0(c("#", sample(c(c(0:9),  LETTERS[1:6]), size = 6, replace = TRUE)), collapse = "")
})

# Simple
d3wordcloud(words, freqs)

# Colors
d3wordcloud(words, freqs, colors = "#FFAA00")
d3wordcloud(words, freqs, colors = colors)
d3wordcloud(words, freqs, colors = c("#000000", "#0000FF", "#FF0000"))
d3wordcloud(words, freqs, colors = substr(viridis::viridis(10, 1), 0 , 7))

# Fonts
d3wordcloud(words, freqs, font = "Erica One", padding = 5)
d3wordcloud(words, freqs, font = "Sigmar One", padding = 7)

# Spiral
d3wordcloud(words,freqs, spiral = "archimedean") # default
d3wordcloud(words,freqs, spiral = "rectangular")

# Scale Size
d3wordcloud(words,freqs, size.scale = "linear") # default
d3wordcloud(words,freqs, size.scale = "log")
d3wordcloud(words,freqs, size.scale = "sqrt")

# Scale Color
## Just work only when you put some colors with length(colors) != length(words)
colors <- substr(viridis::viridis(3), 0 , 7)
d3wordcloud(words,freqs, colors = colors, color.scale = "linear") # default
d3wordcloud(words,freqs, colors = colors, color.scale = "log")
d3wordcloud(words,freqs, colors = colors, color.scale = "sqrt")

# Rotation
d3wordcloud(words, freqs, rotate.min = 0, rotate.max = 0)
d3wordcloud(words, freqs, rotate.min = 45, rotate.max = 45)
d3wordcloud(words, freqs, rotate.min = -180, rotate.max = 180)

# tooltip
d3wordcloud(words, freqs, tooltip = TRUE)


## End(Not run)

jbkunst/d3wordcloud documentation built on May 18, 2019, 5:59 p.m.