venneuler中的图例venn图
我想为venneuler-venn图创建一个图例。这应该是直截了当的,因为函数venneuler将返回用于控制台的颜色。颜色的值介于0和1之间。我想知道如何将存储在$colors中的数字值转换为可以用来填充图例中的fill参数的值 下面我尝试使用从venneuler提取的$colors和从colors()索引。我知道这是不正确的,因为colors()是用区间值编制索引的,但把它放进去是为了显示我想要的venneuler中的图例venn图,r,venn-diagram,R,Venn Diagram,我想为venneuler-venn图创建一个图例。这应该是直截了当的,因为函数venneuler将返回用于控制台的颜色。颜色的值介于0和1之间。我想知道如何将存储在$colors中的数字值转换为可以用来填充图例中的fill参数的值 下面我尝试使用从venneuler提取的$colors和从colors()索引。我知道这是不正确的,因为colors()是用区间值编制索引的,但把它放进去是为了显示我想要的 set.seed(20) x <- matrix(sample(0:1, 100, re
set.seed(20)
x <- matrix(sample(0:1, 100, replace = TRUE), 10, 10)
colnames(x) <- LETTERS[1:10]
rownames(x) <- letters[1:10]
require(venneuler)
y <- venneuler(x)
plot(y)
y$colors
legend(.05, .9, legend = colnames(x), fill = colors()[y$colors])
set.seed(20)
x通过阅读plot.VennDiagram
及其默认值,您可以看到它如何将y$colors
中的数字转换为rgb颜色字符串。(请尝试getAnywhere(“plot.VennDiagram”)
亲自查看。)
在这里,我收集了两位代码,它们将颜色(在您的例子中)处理为一个函数,该函数将为您进行转换。传奇的定位可能会有所改进,但这是另一个问题
col.fn <- function(col, alpha=0.3) {
col<- hcl(col * 360, 130, 60)
col <- col2rgb(col)/255
col <- rgb(col[1, ], col[2, ], col[3, ], alpha)
col
}
COL <- col.fn(y$colors)
# The original order of columns in x is jumbled in the object returned
# by venneuler. This code is needed to put the colors and labels back
# in the original order (here alphabetical).
LABS <- y$labels
id <- match(colnames(x), LABS)
plot(y)
legend(.05, .9, legend = LABS[id], fill = COL[id], x="topleft")
col.fn我使用了id