我正在嘗試使用 circlize 包創建一個圓形圖。使用十六進制顏色代碼時,我的繪圖不會顯示任何內容,但是當我使用實際顏色名稱時,它會顯示。這是為什么?
代碼:
suppressPackageStartupMessages({
library(tidyverse)
library(circlize)
})
# input data
dput(annot)
structure(list(Case_type = c("Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "Initial CNS Tumor",
"Initial CNS Tumor", "Initial CNS Tumor", "no evidence of disease",
"no evidence of disease", "no evidence of disease", "Progressive",
"Progressive", "Progressive", "Progressive", "Progressive", "Progressive",
"Progressive", "Progressive", "Progressive", "Progressive", "Recurrence",
"Recurrence", "Recurrence", "Recurrence", "Recurrence", "Recurrence",
"Recurrence", "Recurrence")), row.names = c("15635-32", "15635-37",
"15635-38", "15635-42", "15635-43", "15635-53", "15635-58", "15635-60",
"15635-63", "15635-70", "15635-75", "15635-80", "15635-87", "15635-100",
"15635-108", "15635-132", "15635-134", "15635-135", "15635-2",
"15635-7", "15635-11", "15635-145", "15635-150", "15635-154",
"15635-161", "15635-169", "15635-170", "15635-187", "15635-197",
"15635-214", "15635-228", "15635-225", "15635-234", "15635-239",
"15635-251", "15635-246", "15635-254", "15635-182", "15635-45",
"15635-46", "15635-68", "15635-90", "15635-101", "15635-127",
"15635-1", "15635-148", "15635-156", "15635-29", "15635-31",
"15635-215", "15635-81", "15635-120", "15635-129", "15635-158",
"15635-279"), class = "data.frame")
# split into 4 categories
split <- factor(annot$Case_type)
circos.clear()
# does not work with the hex color codes
col_fun1 <- list('Initial CNS Tumor' = '#59acff',
'Recurrence' = '#ffac59',
'Progressive' = '#ffff59',
'no evidence of disease' = '#acff59')
circos.par(start.degree = 30, gap.degree = 1, points.overflow.warning = FALSE)
circos.heatmap(annot,
split = split,
col = col_fun1,
track.height = 0.4,
bg.border = "gray50",
show.sector.labels = T)
circos.clear()

當我使用非十六進制顏色名稱時,它可以作業:
# this works
col_fun2 <- list('Initial CNS Tumor' = 'yellow',
'Recurrence' = 'blue',
'Progressive' = 'green',
'no evidence of disease' = 'orange')
circos.par(start.degree = 30, gap.degree = 1, points.overflow.warning = FALSE)
circos.heatmap(annot,
split = split,
col = col_fun2,
track.height = 0.4,
bg.border = "gray50",
show.sector.labels = T)
circos.clear()

uj5u.com熱心網友回復:
根據檔案,在描述論點時col
如果值是字符,顏色應該是一個命名的顏色向量。
而您傳遞的是串列而不是命名向量。因此,如果您(或使用而不是unlist col_fun1創建它),您會得到c()list()
circos.par(start.degree = 30, gap.degree = 1, points.overflow.warning = FALSE)
circos.heatmap(annot,
split = split,
col = unlist(col_fun1),
track.height = 0.4,
bg.border = "gray50",
show.sector.labels = T)
circos.clear()

我的困惑是為什么第一個版本有效,而不是為什么第二個版本無效。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/445263.html
