有人在R中使用wordcloud2添加自定义颜色吗?它在小插图中说您可以添加颜色矢量作为输入,但是没有给出示例。当我尝试执行此操作(包含以下代码)时,颜色与正确的单词不匹配。
我正在尝试用适当的颜色为风味词上色(有些缺失,因为我没有机会将它们全部添加)。
有什么想法吗?预先感谢!
library(wordcloud2)
flavours <- structure(
list(
words = c(
"\"blackcherry", "\"bourbon", "\"burnttoast",
"\"caramel", "\"honey", "berries", "blueberry", "burnttoast",
"butter", "c(\"redgrape", "canesugar", "caramel", "carbon",
"cherry",
"cola", "cola\"", "cream", "darkchocolate", "darkchocolate\"",
"driedfruit\"", "ginger", "ginger\"\n)", "grape\"", "greenapple",
"greengrape", "honeycomb", "lime", "milkchocolate", "raisin",
"redgrape", "toffee", "vanilla", "whitepepper", "whitewine\"",
"wine\""),
freq = c(
1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 3L, 1L, 1L, 1L, 1L, 9L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
4L, 2L, 1L, 1L, 1L, 2L, 1L, 1L),
colour = c(
"#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#283747", "#755852",
"#ffff00", "#000000", "#E5E7E9", "#ffff00", "#515A5A", "#C0392B",
"#755852", "#000000", "#ffff00", "#755852", "#000000", "#000000",
"#755852", "#000000", "#000000", "#58D68D", "#58D68D", "#ffff00",
"#58D68D", "#755852", "#755852", "#6C3483", "#D4AC0D", "#ffff00",
"#E5E7E9", "#000000", "#000000")),
class = "data.frame", row.names = c(NA, -35L))
wordcloud2(data = flavours[,1:2], color = flavours[,3])