如何解决chordDiagram中的col2rgb(col,alpha = TRUE)中的错误?

时间:2019-05-24 12:36:06

标签: r colors rgb chord-diagram circlize

这是我的data.frame df1

                   from                 to value
  1   HatcheryVsGambier     KatiuVsGambier  5760
  2   HatcheryVsGambier    KatiuVsHatchery  5331
  3          RedVsGreen  HatcheryVsGambier  1097
  4   HatcheryVsGambier  TakapotoVsGambier  5897
  5   HatcheryVsGambier TakapotoVsHatchery  5195
  6   HatcheryVsGambier    TakapotoVsKatiu  1425
  7       YellowVsGreen  HatcheryVsGambier  1153
  8         YellowVsRed  HatcheryVsGambier  1161
  9      KatiuVsGambier    KatiuVsHatchery  8961
  10         RedVsGreen     KatiuVsGambier  1260
  11     KatiuVsGambier  TakapotoVsGambier  9597
  12     KatiuVsGambier TakapotoVsHatchery  4078
  13     KatiuVsGambier    TakapotoVsKatiu  5090
  14      YellowVsGreen     KatiuVsGambier  1357
  15        YellowVsRed     KatiuVsGambier  1295
  16         RedVsGreen    KatiuVsHatchery  1267
  17    KatiuVsHatchery  TakapotoVsGambier  4192
  18    KatiuVsHatchery TakapotoVsHatchery  9894
  19    KatiuVsHatchery    TakapotoVsKatiu  5263
  20      YellowVsGreen    KatiuVsHatchery  1361
  21        YellowVsRed    KatiuVsHatchery  1364
  22         RedVsGreen  TakapotoVsGambier  1289
  23         RedVsGreen TakapotoVsHatchery  1333
  24         RedVsGreen    TakapotoVsKatiu  1181
  25  TakapotoVsGambier TakapotoVsHatchery 10319
  26  TakapotoVsGambier    TakapotoVsKatiu  5728
  27      YellowVsGreen  TakapotoVsGambier  1387
  28        YellowVsRed  TakapotoVsGambier  1346
  29 TakapotoVsHatchery    TakapotoVsKatiu  5589
  30      YellowVsGreen TakapotoVsHatchery  1374
  31        YellowVsRed TakapotoVsHatchery  1385
  32      YellowVsGreen    TakapotoVsKatiu  1197
  33        YellowVsRed    TakapotoVsKatiu  1213
  34      YellowVsGreen        YellowVsRed  3564
  35         RedVsGreen      YellowVsGreen  3240
  36         RedVsGreen        YellowVsRed  3622

我想创建一个chordDiagram,并特别强调3个比较: RedVsGreenYellowVsGreenYellowVsRed

这是我的代码:

 grid.col = c(YellowVsRed=   "forestgreen",
              KatiuVsGambier=   "grey",
              KatiuVsHatchery=   "grey",
              RedVsGreen=   "forestgreen",
              TakapotoVsGambier=   "grey",
              TakapotoVsHatchery=   "grey",
              YellowVsGreen=   "forestgreen",
              TakapotoVsKatiu=   "grey",
              HatcheryVsGambier=   "grey")


 # like Figure 13.14: Set line style as a data frame in https://jokergoo.github.io/circlize_book/book/the-chorddiagram-function.html#chord-diagram-colors
 lty_df = data.frame(c("RedVsGreen", "RedVsGreen", "YellowVsGreen"), 
                     c("YellowVsGreen", "YellowVsRed", "YellowVsRed"), 
                     c(1, 2, 3))
 lwd_df = data.frame(c("RedVsGreen", "RedVsGreen", "YellowVsGreen"), 
                     c("YellowVsGreen", "YellowVsRed", "YellowVsRed"), 
                     c(2, 2, 2))
 border_df = data.frame(c("RedVsGreen", "RedVsGreen", "YellowVsGreen"), 
                        c("YellowVsGreen", "YellowVsRed", "YellowVsRed"), 
                        c(1, 1, 1))

 # like Figure 13.17: Highlight links by data frame in https://jokergoo.github.io/circlize_book/book/the-chorddiagram-function.html#chord-diagram-colors
 col_df = data.frame(c("RedVsGreen", "RedVsGreen", "YellowVsGreen"), c("YellowVsGreen", "YellowVsRed", "YellowVsRed"), c("#FF000080", "#00FF0080", "#0000FF80"))
 col_df = data.frame(c("RedVsGreen", "RedVsGreen", "YellowVsGreen"), c("YellowVsGreen", "YellowVsRed", "YellowVsRed"), c("goldenrod4", "green", "blue"))
 col_df = data.frame(c("RedVsGreen", "RedVsGreen", "YellowVsGreen"), c("YellowVsGreen", "YellowVsRed", "YellowVsRed"), c(palette = 1:3))


 chordDiagram(df1, grid.col = grid.col, col = col_df, link.lty = lty_df, link.lwd = lwd_df, link.border = border_df, order = c("YellowVsRed",
                                                                                                                               "KatiuVsGambier",
                                                                                                                               "KatiuVsHatchery",
                                                                                                                               "RedVsGreen",
                                                                                                                               "TakapotoVsGambier",
                                                                                                                               "TakapotoVsHatchery",
                                                                                                                               "YellowVsGreen",
                                                                                                                               "TakapotoVsKatiu",
                                                                                                                               "HatcheryVsGambier"))

当我尝试为三个比较之间的“链接”添加特定颜色时,出现了我的问题。添加特定的线型有效(请参见下图),但颜色无效。 R发送此消息:

Error in col2rgb(col, alpha = TRUE) : nom de couleur 'c(1, 1, 2)' incorrecte

英语为invalid color name

我尝试使用与手册here中相同的颜色语言,其他人(如您所见,仍然可以看到此错误)。

  • 我尝试过多次重新启动R和计算机。
  • 我从其他线程stackoverflow1stackoverflow2或再次here尝试了这些解决方案,但无济于事。
  • 我还进入了chordDiagramFromDataFrame()包的circlize函数,将col2rgb(col, alpha = TRUE)更改为col2rgb(col, alpha = FALSE),但这都不起作用。

这是我在没有chordDiagram()参数的情况下获得的col = col_df

chorDiagramPlot

0 个答案:

没有答案
相关问题