R 包 circlize:Circos 热图颜色未显示

发布于 2025-01-14 17:01:02 字数 3495 浏览 4 评论 0原文

我正在尝试使用 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()

在此处输入图像描述

I am trying to create a circular plot using circlize package. When using hex color codes, my plot does not show up anything but when I use actual color names, it shows. Why is that?

Code:

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()

enter image description here

When I use non-hex color names, it works:

# 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()

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花坊 2025-01-21 17:01:02

根据文档,在描述参数 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()

输入图片此处描述

谜题对我来说,这就是为什么第一个版本有效,而不是第二个版本无效的原因。

According to the docs, when describing the argument col

If the values are characters, the color should be a named color vector.

Whereas you are passing a list rather than a named vector. So if you unlist col_fun1 (or create it with c() instead of list()), you get

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()

enter image description here

The puzzle for me is why the first version works, not why the second one doesn't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文