摆脱wordcoud,开始新的gg词云图绘制,官方网站 https://lepennec.github.io/ggwordcloud/articles/ggwordcloud.html
# install.packages("devtools")# install if necessary
# library(devtools)
# package: rtools may be needed, but can not be install correctly
# you should download the package from https://cran.r-project.org/bin/windows/Rtools/
# choose the right version, according to your system
# goodluck
# install.packages("ggwordcloud")
# load the data
# install.packages("ggplot2",dependencies = TRUE)
# install.packages("vctrs")
library(ggplot2)
library(ggwordcloud)
data("love_words_small")
data("love_words")
# check the data
head(love_words_small)
## # A tibble: 6 x 4
## lang word native_speakers speakers
## <chr> <chr> <dbl> <dbl>
## 1 zh 愛 1200 1200
## 2 en Love 400 800
## 3 es Amor 480 555
## 4 ar <U+062D><U+0628> 245 515
## 5 hi <U+092A><U+094D><U+092F><U+093E><U+0930> 322 442
## 6 fr Amour 76.8 351.
绘图基于ggplot,上述的代码其实主要是为了获得所需数据集
set.seed(42)
ggplot(love_words_small, aes(label = word, size = speakers)) +
geom_text_wordcloud_area(shape = "star") +
scale_size_area(max_size = 40) +
theme_minimal()
错了,是比个星星
ggplot(
love_words_small,
aes(
label = word, size = speakers,
color = factor(sample.int(10, nrow(love_words_small), replace = TRUE)))) +
geom_text_wordcloud_area() +
scale_size_area(max_size = 40) +
theme_minimal()
set.seed(42)
ggplot(love_words_small, aes(label = word, size = speakers,
color = factor(sample.int(10, nrow(love_words_small), replace = TRUE)))) +
geom_text_wordcloud_area(
mask = png::readPNG(system.file("extdata/hearth.png",
package = "ggwordcloud", mustWork = TRUE
)),
rm_outside = TRUE
) +
scale_size_area(max_size = 40) +
theme_minimal()
## One word could not fit on page. It has been removed.
gg的词云比之前的wordcoloud的功能强大很多,更多的功能需要各位看官自行挖掘,人生苦短,且行且珍惜,peace&love.
最后加个投票,自公众号更新至此,前期一直保证一天一篇,疫情原因闲置在家,一直提不起精神,也没有多少想法,运营这个公众号,一直以来都是当做学习笔记来完成,现在觉得有点累了,朋友也罢,好友也罢,生活并没有给我多少快乐。最后想看看这个公众号有多少人觉得有帮助,如果不多的话,后续就不在公众号发自己的笔记了,专心github。