Stataq
Stataq

Reputation: 2297

how to use self define color groups in word cloud

I would like to define a color groups for my graph.

Here is the color groups that I got: enter image description here

Now I would like to create wordcloud using this color groups and how should I modify wordcloud codes:

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")

currently , it is just black. I want to use my self define color group. to

Upvotes: 1

Views: 152

Answers (1)

Edward
Edward

Reputation: 18838

Your functions are nice. To use them I think you can just do the following:

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")

enter image description here

Upvotes: 1

Related Questions