gpt4 book ai didi

r - 使用包 ‘nVennR’ 转换数据以创建广义的准比例维恩图

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:36:26 27 4
gpt4 key购买 nike

我有以下数据集,希望您帮助转换它,以便能够使用 Package ‘nVennR’ 绘制维恩图通过 Pérez-Silva et al. 2018 .

这是数据集:

dput(data)
structure(list(Employee = c("A001", "A002", "A003", "A004", "A005",
"A006", "A007", "A008", "A009", "A010", "A011", "A012", "A013",
"A014", "A015", "A016", "A017", "A018"), SAS = c("Y", "N", "Y",
"Y", "Y", "Y", "N", "Y", "N", "N", "Y", "Y", "Y", "Y", "N", "N",
"N", "N"), Python = c("Y", "Y", "Y", "Y", "N", "N", "N", "N",
"N", "N", "Y", "Y", "N", "N", "N", "N", "Y", "Y"), R = c("Y",
"Y", "N", "Y", "N", "Y", "N", "N", "Y", "Y", "Y", "Y", "Y", "Y",
"Y", "Y", "N", "N")), .Names = c("Employee", "SAS", "Python",
"R"), row.names = c(NA, -18L), class = c("tbl_df", "tbl", "data.frame"
))

请看下面我想要得到的维恩图示例:

enter image description here

更新:

安装更新版本的 nVennRrsvg 后,当我运行来自 here 的示例代码时我得到以下错误和图表:

Warning message:
In checkValidSVG(doc, warn = warn) :
This picture was not generated by the 'grConvert' package, errors may result

enter image description here

以下是我的 session 信息:

sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base

other attached packages:
[1] nVennR_0.2.0

loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 lattice_0.20-35 XML_3.98-1.10
[4] png_0.1-7 rsvg_1.1 grid_3.4.2
[7] plyr_1.8.4 gtable_0.2.0 scales_0.5.0.9000
[10] ggplot2_2.2.1.9000 pillar_1.2.1 rlang_0.2.0.9001
[13] grImport2_0.1-2 lazyeval_0.2.1 Matrix_1.2-12
[16] tools_3.4.2 munsell_0.4.3 jpeg_0.1-8
[19] compiler_3.4.2 base64enc_0.1-3 colorspace_1.3-2
[22] tibble_1.4.2

如果有任何解决此问题的想法,我将不胜感激。

最佳答案

这是在 Bioconductor 中使用 limma 包的一种方法,您的数据从 dput 加载为变量 z:

source("http://www.bioconductor.org/biocLite.R")
biocLite("limma")
library(limma)

将所有 Y 更改为 TRUE,将所有 N 更改为 FALSE:

z2 <- data.frame(lapply(z, function(x) { gsub("Y", "TRUE", x) }))
z3 <- data.frame(lapply(z2, function(x) { gsub("N", "FALSE", x) }),stringsAsFactors=FALSE)

确保它们都是逻辑类型:

z3$SAS <- as.logical(z3$SAS)
z3$Python <- as.logical(z3$Python)
z3$R <- as.logical(z3$R)

现在使用 vennCounts 计算每个 Venn 区域的所有总数:

> ( venn.totals <- vennCounts(z3[,-1]) )
SAS Python R Counts
1 0 0 0 1
2 0 0 1 4
3 0 1 0 2
4 0 1 1 1
5 1 0 0 2
6 1 0 1 3
7 1 1 0 1
8 1 1 1 4
attr(,"class")
[1] "VennCounts"

生成图表只是又一步:

vennDiagram(venn.totals)

enter image description here

关于r - 使用包 ‘nVennR’ 转换数据以创建广义的准比例维恩图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49471565/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com