-
Notifications
You must be signed in to change notification settings - Fork 8
/
README.Rmd
110 lines (91 loc) · 3.05 KB
/
README.Rmd
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.dev = "grDevices::png",
dpi = 96L,
dev.args = list(),
fig.ext = "png",
fig.width = 700 / 96,
fig.height = NULL,
fig.retina = 2L,
fig.asp = 1 / 1.618,
fig.align = "center"
)
```
# ggwordcloud <img src="man/figures/logo.png" align="right" height=140/>
[![CRAN status](https://www.r-pkg.org/badges/version/ggwordcloud)](https://cran.r-project.org/package=ggwordcloud)
`ggwordcloud` provides a word cloud text geom for `ggplot2`. The placement algorithm implemented in C++ is an hybrid between the one of `wordcloud` and the one of `wordcloud2.js`. The cloud can grow according to a shape and stay within a mask. The size aesthetic is used either to control the font size or the printed area of the words. `ggwordcloud` also supports arbitrary text rotation. The faceting scheme of `ggplot2` can also be used. Two functions meant to be the equivalent of `wordcloud` and `wordcloud2` are proposed. Last but not least you can use `gridtext` markdown/html syntax in the labels.
## Installation
You can install the released version of ggwordcloud from [CRAN](https://CRAN.R-project.org) with:
```{r, eval=FALSE}
install.packages("ggwordcloud")
```
or the development version from the github repository
```{r, eval=FALSE}
devtools::install_github("lepennec/ggwordcloud")
```
Please check the latest development version before submitting an issue.
# Some word clouds
Because sometimes, pictures are better than a thousand words...
```{r}
library(ggwordcloud)
data("love_words_small")
set.seed(42)
ggplot(love_words_small, aes(label = word, size = speakers)) +
geom_text_wordcloud() +
scale_size_area(max_size = 40) +
theme_minimal()
```
```{r}
data("love_words")
set.seed(42)
ggplot(
love_words,
aes(
label = word, size = speakers,
color = speakers
)
) +
geom_text_wordcloud_area(aes(angle = 45 * sample(-2:2, nrow(love_words),
replace = TRUE,
prob = c(1, 1, 4, 1, 1)
)),
mask = png::readPNG(system.file("extdata/hearth.png",
package = "ggwordcloud", mustWork = TRUE
)),
rm_outside = TRUE
) +
scale_size_area(max_size = 40) +
theme_minimal() +
scale_color_gradient(low = "darkred", high = "red")
```
```{r}
library(dplyr, quietly = TRUE, warn.conflicts = FALSE)
library(tidyr, quietly = TRUE)
set.seed(42)
ggplot(
love_words_small %>%
gather(key = "type", value = "speakers", -lang, -word) %>%
arrange(desc(speakers)),
aes(label = word, size = speakers)
) +
geom_text_wordcloud_area() +
scale_size_area(max_size = 40) +
theme_minimal() +
facet_wrap(~type)
```
```{r}
set.seed(42)
ggplot(love_words_small, aes(label = word, size = speakers,
label_content = sprintf("%s<span style='font-size:7.5pt'>(%g)</span>", word, speakers))) +
geom_text_wordcloud_area() +
scale_size_area(max_size = 40) +
theme_minimal()
```
More examples are available in the vignette.