使用 R 或 Excel 重叠图表

发布于 2024-11-14 01:25:08 字数 260 浏览 5 评论 0原文

我有以下矩阵,我想使用 R (首选)或 Excel 绘制重叠图。

    a       b       c
a   1       0.5     0.7
b   0.5     1       0.4
c   0.7     0.4     1

例如,上表显示 ab 重叠率为 50%,而 ac 重叠率为 70% %。

I have following matrix and I want to draw overlapping graph using R (preferable) or Excel.

    a       b       c
a   1       0.5     0.7
b   0.5     1       0.4
c   0.7     0.4     1

For example, the above table shows that a and b have 50% overlapping, whereas a and c have 70%.

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

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

发布评论

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

评论(1

云淡月浅 2024-11-21 01:25:08

如果您想要重叠,那么您错过了一个数字 - 重叠所有三个:abc

正如 Aniko 在评论中所写,您可以使用维恩图,例如 来自 R-forge 的 Vennerable。

安装需要 BioConductor 中的一些软件包:

source("http://bioconductor.org/biocLite.R")
biocLite(c("graph", "RBGL", "gtools", "xtable"))
install.packages("Vennerable", repos="http://R-Forge.R-project.org")

您必须正确准备数据:

require(Vennerable)
x <- Venn(
    SetNames = c("a", "b", "c"),
    Weight = c(`100`=1,   `010`=1,   `001`=1,
               `110`=0.5, `101`=0.7, `011`=0.4,
               `111`=.5) # I made this up cause your question miss it
)

瞧:

plot(x, doWeights=TRUE)

维恩图


一些额外的解释。

Vennerable 包的数据结构需要提供集合名称(在您的情况下为 "a""b""c")和频率/每个相交的比例。此 0/1 名称标识子集:1 表示“在集合中”,0 表示“不在集合中”。例如:

  • 100 表示在 a 中,不在 b 中,不在 c 中,
  • 011 表示不在 a 中,在 b 中,在 c

,所以 111 表示在所有三个集合中,即您的矩阵中缺少它,并且无法将其添加到那里。对于您的样本数据,当 a&b 有 0.7 重叠且 b&c 有 0.4 时,意味着至少 0.1 同时位于三个集合中(或者我错过了对这个数字的解释)。 (注意:我认为我高估了这个 0.5,因为它应该低于 0.4)

您可以在创建矩阵之前将数据准备到维恩图,例如:

X <- list(
    a = c("One", "Two", "Three"),
    b = c("One", "Three", "Four", "Five", "Seven"),
    c = c("Three", "Five", "Eight", "Nine", "Ten")
)

x <- Venn(X)
x
# A Venn object on 3 sets named
# a,b,c 
# 000 100 010 110 001 101 011 111 
#   0   1   2   1   3   0   1   1 
plot(x, doWeights=TRUE)

If you want overlapping then you missed one number - overlapping all three: a, b, c.

As Aniko write in comment you could use Venn diagrams, e.g. Vennerable from R-forge.

Installation need some packages from BioConductor:

source("http://bioconductor.org/biocLite.R")
biocLite(c("graph", "RBGL", "gtools", "xtable"))
install.packages("Vennerable", repos="http://R-Forge.R-project.org")

You mast prepare your data properly:

require(Vennerable)
x <- Venn(
    SetNames = c("a", "b", "c"),
    Weight = c(`100`=1,   `010`=1,   `001`=1,
               `110`=0.5, `101`=0.7, `011`=0.4,
               `111`=.5) # I made this up cause your question miss it
)

And voilà:

plot(x, doWeights=TRUE)

Venn diagram


Some additional explanations.

Data structures for Vennerable package need to provide set names ("a", "b", "c" in your case) and frequencies/proportions of each intersects. This 0/1 names identify subsets: 1 means "in set", 0 means "not in set". So e.g.:

  • 100 means in a, not in b, not in c,
  • 011 means not in a, in b, in c

So 111 means in all three sets, which is missing in your matrix and it can't be added there. For your sample data when a&b has 0.7 overlapping and b&c has 0.4 means that at least 0.1 is in three set at the same time (or I missed interpretation of this numbers). (note: I think I overestimated this 0.5, cause it should be lower than 0.4)

You could prepare your data to Venn plot before creating matrix, e.g:

X <- list(
    a = c("One", "Two", "Three"),
    b = c("One", "Three", "Four", "Five", "Seven"),
    c = c("Three", "Five", "Eight", "Nine", "Ten")
)

x <- Venn(X)
x
# A Venn object on 3 sets named
# a,b,c 
# 000 100 010 110 001 101 011 111 
#   0   1   2   1   3   0   1   1 
plot(x, doWeights=TRUE)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文