R - wordcloud包没有正确应用给定的颜色

时间:2016-05-10 20:29:01

标签: r word-cloud

我想使用以下<select name="department" form="quickcontact_frm"> <option value="default">Select </option> <option value="1"><?php echo $params->get('department1');?></option> <option value="2"><?php echo $params->get('department2');?></option> <option value="3"><?php echo $params->get('department3');?></option> <option value="4" selected><?php echo $params->get('department4');?></option> <option value="5"><?php echo $params->get('department5');?></option> <option value="6"><?php echo $params->get('department6');?></option> <option value="7"><?php echo $params->get('department7');?></option> <option value="8"><?php echo $params->get('department8');?></option> </select> pngwordcloud创建vector of colors

colorVector <- c("#797978", "#797978", "#797978", "#797978", "#797978", "#797978", 
"#FF6633", "#FF6633", "#797978", "#797978", "#797978", "#797978", 
"#00FF99", "#797978", "#797978", "#797978", "#797978", "#797978", 
"#00FF99", "#797978", "#797978", "#797978", "#797978", "#797978", 
"#797978", "#797978", "#797978", "#797978", "#00FF99", "#FF6633"
)

# Create wordcloud and save the image in png format
png("wcMM.png", width=7.5, height=5.5, units="cm", res=140, bg = "white")
wordcloud(words = topfeaturesF$keyName, 
          freq = topfeaturesF$value.x, 
          scale=c(3,.9),
          min.freq=2,max.words=50, 
          random.order=T, rot.per=.25, 
          colors=topfeaturesF$color, 
          family ="Verdana")
dev.off()

虽然wordcloud变色,但它们(颜色)并没有应用于正确的单词,如下图所示,似乎属性colors表现得很奇怪,就像在矢量只有3个橙子和3个绿色定义,但1个绿色和7个橙子&#34;画&#34;:

enter image description here

来自wordcloud包文档:

  

colors =从最少到最频繁的颜色词

我是否错过了解颜色属性的工作原理?

数据帧:

topfeaturesF <- structure(list(keyName = structure(c(26L, 20L, 4L, 18L, 8L, 12L, 
    22L, 7L, 21L, 11L, 17L, 3L, 29L, 14L, 30L, 16L, 28L, 27L, 2L, 
    25L, 6L, 24L, 9L, 1L, 13L, 19L, 5L, 23L, 10L, 15L), .Label = c("bas", 
    "corporation", "deutsch", "deutschland", "digital", "erst", "euro", 
    "fil", "gibt", "gmbh", "jahr", "kund", "lte", "mobil", "mod", 
    "monat", "netz", "neu", "nutz", "o2", "plus", "program", "prozent", 
    "schon", "tarif", "telefonica", "telekom", "unternehm", "windows", 
    "wurd"), class = "factor"), id = structure(c(26L, 20L, 4L, 18L, 
    8L, 12L, 22L, 7L, 21L, 11L, 17L, 3L, 29L, 14L, 30L, 16L, 28L, 
    27L, 2L, 25L, 6L, 24L, 9L, 1L, 13L, 19L, 5L, 23L, 10L, 15L), .Label = c("bas42461", 
    "corporation42461", "deutsch42461", "deutschland42461", "digital42461", 
    "erst42461", "euro42461", "fil42461", "gibt42461", "gmbh42461", 
    "jahr42461", "kund42461", "lte42461", "mobil42461", "mod42461", 
    "monat42461", "netz42461", "neu42461", "nutz42461", "o242461", 
    "plus42461", "program42461", "prozent42461", "schon42461", "tarif42461", 
    "telefonica42461", "telekom42461", "unternehm42461", "windows42461", 
    "wurd42461"), class = "factor"), value.x = c(2907, 1400, 1239, 
    998, 810, 701, 689, 685, 615, 592, 585, 543, 540, 532, 523, 504, 
    472, 472, 468, 467, 464, 460, 432, 392, 373, 372, 368, 347, 338, 
    336), date = c(42461, 42461, 42461, 42461, 42461, 42461, 42461, 
    42461, 42461, 42461, 42461, 42461, 42461, 42461, 42461, 42461, 
    42461, 42461, 42461, 42461, 42461, 42461, 42461, 42461, 42461, 
    42461, 42461, 42461, 42461, 42461), value.y = c(2430L, 1576L, 
    780L, 886L, 883L, 648L, 812L, 787L, 614L, 566L, 567L, 355L, 301L, 
    328L, 552L, 515L, 323L, 387L, 190L, 426L, 294L, 354L, 335L, 342L, 
    254L, 241L, 265L, 212L, 203L, NA), diff = c(0.196296296296296, 
    -0.111675126903553, 0.588461538461538, 0.126410835214447, -0.0826727066817667, 
    0.0817901234567902, -0.151477832512315, -0.129606099110546, 0.00162866449511401, 
    0.0459363957597174, 0.0317460317460319, 0.529577464788732, 0.794019933554817, 
    0.621951219512195, -0.052536231884058, -0.0213592233009708, 0.461300309597523, 
    0.219638242894057, 1.46315789473684, 0.096244131455399, 0.578231292517007, 
    0.299435028248588, 0.28955223880597, 0.146198830409357, 0.468503937007874, 
    0.543568464730291, 0.388679245283019, 0.636792452830189, 0.665024630541872, 
    NA), color = c("#797978", "#797978", "#797978", "#797978", "#797978", 
    "#797978", "#FF6633", "#FF6633", "#797978", "#797978", "#797978", 
    "#797978", "#00FF99", "#797978", "#797978", "#797978", "#797978", 
    "#797978", "#00FF99", "#797978", "#797978", "#797978", "#797978", 
    "#797978", "#797978", "#797978", "#797978", "#797978", "#00FF99", 
    "#FF6633")), .Names = c("keyName", "id", "value.x", "date", "value.y", 
    "diff", "color"), row.names = c(26L, 20L, 4L, 18L, 8L, 12L, 22L, 
    7L, 21L, 11L, 17L, 3L, 29L, 14L, 30L, 16L, 28L, 27L, 2L, 25L, 
    6L, 24L, 9L, 1L, 13L, 19L, 5L, 23L, 10L, 15L), class = "data.frame")

1 个答案:

答案 0 :(得分:2)

您可能正在寻找ordered.colors参数:

library(wordcloud)
wordcloud(words = topfeaturesF$keyName, 
          freq = topfeaturesF$value.x, 
          scale=c(3,.9),
          min.freq=2,max.words=50, 
          random.order=T, rot.per=.25, 
          colors=topfeaturesF$color,
          ordered.colors=TRUE,
          family ="Verdana")

enter image description here