【问题标题】:legend venn diagram in venneulervenneuler 中的图例维恩图
【发布时间】:2012-02-03 00:11:32
【问题描述】:

我想为venneuler venn 图创建一个图例。这应该是直截了当的,因为函数 venneuler 将使用的颜色返回给控制台。颜色的值介于 0 和 1 之间。我想知道如何将存储在 $colors 中的这些数字值转换为可用于填充图例中的填充参数的东西。

我通过使用从venneuler 中提取的$colors 并从colors() 中进行索引来尝试此操作。我知道这是不正确的,因为 colors() 是用区间值索引的,但将其放入以显示我想要的内容。

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

【问题讨论】:

    标签: r venn-diagram


    【解决方案1】:

    通过阅读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")
    

    【讨论】:

    • 我改用id &lt;- match(names(y$colors, LAB))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多