I'm creating a wordcloud in which the size of the words is based on frequency, but i want the colour of the words to be defined by a variable (a string). The aim is to join two types of a dataset in one wordcloud and to differentiate by color. For example, if the type is 'Job' the word appear with the colour blue (#297FD5) and if it's 'Tal' appear with the color grey (#595959).
I tried the following, which gave me the colour defined by the code and not what i want.
AllWords <- data.frame(word = c("Database", "Database", "Javascript","Javascript", "Java", "Java", "CSS", "CSS"),
scale = c(1.007728, 1.111018, 11.892040, 14.085705, 8.031906, 11.009304, 5.026064, 9.257963 ),
type = c("Job", "Tal","Job", "Tal","Job", "Tal","Job", "Tal"),
df_color = c("#297FD5", "#595959","#297FD5", "#595959","#297FD5", "#595959","#297FD5", "#595959"))
#Packages
library(ggwordcloud)
library(ggplot2)
library(dplyr, quietly = TRUE)
library(dplyr, quietly = TRUE, warn.conflicts = FALSE)
library(tidyr, quietly = TRUE)
#Wordcloud
set.seed(42)
ggplot(
AllWords,
aes(
label = word,
size = scale,
color = df_color
)) +
geom_text_wordcloud_area(rm_outside = TRUE, eccentricity = 1) +
scale_size_area(max_size = 10) +
theme_minimal()
Does anyone know how i can change the color for the words depending from a string? Thanks!

