我使用ggwordcloud
创建了一个词云,因为不幸的是我无法使用替代的词云包。到目前为止,我能够根据我的要求自定义 ggwordcloud,但遗憾的是我错过了淡入透明的渐变的实现。到目前为止我还没有找到允许这样做的函数。
下面的代码创建了wordcloud
,但只有两种颜色,但我需要一个渐变,它越来越透明(如第二个代码示例中所示),以便最小的单词是隐藏/透明的。
library(ggwordcloud)
data("love_words_small")
data("love_words")
set.seed(42)
ggplot(
love_words_small,
aes(
label = word, size = speakers,
color = speakers
)
) +
geom_text_wordcloud_area() +
scale_size_area(max_size = 24) +
theme_minimal() +
scale_color_gradient(low = "darkred", high = "red")
通过 quanteda
Wordcloud
包实现的以下实现已经使用 adjustcolor
解决了我迄今为止的问题:
library(quanteda)
library(quanteda.textplots)
set.seed(10)
dfmat1 <- dfm(corpus_subset(data_corpus_inaugural, President == "Obama"),
remove = stopwords("english"), remove_punct = TRUE) %>%
dfm_trim(min_termfreq = 3)
col <- sapply(seq(0.1, 1, 0.1), function(x) adjustcolor("#1F78B4", x))
textplot_wordcloud(dfmat1, adjust = 0.5, random_order = FALSE,
color = col, rotation = FALSE)
有什么办法可以将此解决方案转移到ggwordcloud
吗?
非常感谢您的建议!
最佳答案
我自己找到了解决方案。太明显了...
col <- sapply(seq(0.1, 1, 0.1), function(x) adjustcolor("#1F78B4", x))
library(ggwordcloud)
data("love_words_small")
data("love_words")
set.seed(42)
ggplot(
love_words_small,
aes(
label = word, size = speakers,
color = speakers
)
) +
geom_text_wordcloud_area() +
scale_size_area(max_size = 24) +
theme_minimal() +
scale_color_gradientn(colours = col)
关于r - 带渐变色/透明字的GGWordcloud(GGPlot Wordcloudgradient with adjustmentcolor),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68297017/