Как исправить ошибку в col2rgb (col, alpha = TRUE) в chordDiagram? - PullRequest
0 голосов
/ 24 мая 2019

Это мой 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 сравнения: RedVsGreen, YellowVsGreen и YellowVsRed.

Так вот мой код:

 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.

Я попробовал тот же цветовой язык, что и в руководстве здесь , и другие, как вы можете видеть, если у меня все еще есть эта ошибка.

  • Я много раз пытался перезапустить R и компьютер.
  • Я пробовал эти решения из других потоков stackoverflow1 , или stackoverflow2 или снова здесь , но ничего не работает ..
  • Я также вхожу в функцию chordDiagramFromDataFrame() пакета circlize, чтобы изменить col2rgb(col, alpha = TRUE) на col2rgb(col, alpha = FALSE), но это тоже не работает ..

Это chordDiagram(), которое я получаю без col = col_df аргументов:

chorDiagramPlot

...