如何在词云中使用自定义颜色组

how to use self define color groups in word cloud

我想为我的图表定义一个颜色组。

这是我得到的颜色组:

现在我想用这个颜色组创建词云,我应该如何修改词云代码:

y<-c("the", "the", "the", "tree", "tree", "tree", "tree", "tree", 
     "tree", "tree", "tree", "tree", "tree", "Wants", "Wants", "Wants", 
     "Wants", "Wants", "Wants", "Wants", "Wants", "Wants", "Wants", 
     "Wants", "Wants", "to~be", "to~be", "to~be", "to~be", "to~be", 
     "to~be", "to~be", "to~be", "to~be", "to~be", "to~be", "to~be", 
     "to~be", "to~be", "to~be", "to~be", "to~be", "to~be", "to~be", 
     "to~be", "when", "when", "when", "when", "when", "familiar", "familiar", 
     "familiar", "familiar", "familiar", "familiar", "familiar", "familiar", 
     "familiar", "familiar", "familiar", "familiar", "familiar", "familiar", 
     "familiar", "familiar", "familiar", "familiar", "familiar", "familiar", 
     "leggings", "leggings", "leggings", "leggings", "leggings", "leggings", 
     "leggings", "leggings", "leggings", "leggings")

layout(matrix(c(1,2,3), nrow=3, ncol=1), heights=c(1,4,1))
par(mar=rep(0,4,))
plot.new()
text(x=0.5,y=0.5, "Title")
set.seed(1234) # for reproducibility 
wordcloud(names(table(y)), table(y))
text(x=0.5,y=0.5, "Date 20200629")

目前,它只是黑色的。我想使用我自己定义的颜色组。

你的功能不错。要使用它们,我认为您可以执行以下操作:

n <- length(table(y) # 7
test_pal()(n)  # The default is your "Blues" palette.
[1] "#1C304C" "#294871" "#366097" "#4578BD" "#769CCE" "#B4C8E4" "#FFFFFF"

layout(matrix(c(1,2,3), nrow=3, ncol=1), heights=c(1,4,1))
par(mar=rep(0,4))
plot.new()
text(x=0.5,y=0.5, "Title")

set.seed(1234) # for reproducibility 
wordcloud(names(table(y)), table(y), colors=test_pal(reverse=TRUE)(n))

plot.new()
text(x=0.5,y=0.05, "Date 20200629")