在r中有一种方法可以在维恩图上为数千个添加逗号分隔符。
venn.plot <- VennDiagram::draw.pairwise.venn(10000, 7000, 3000, c("First", "Second"), scaled = FALSE)
grid::grid.draw(venn.plot)
结果图表如下所示。
看起来这个功能不是为了做到这一点。如果你真的想使用这个功能,你可以“破解”它来替换它用于标签的默认格式代码。请注意,此方法非常脆弱,因为我们正在编辑特定的代码“行”。首先复制一下这个函数
myvenn <- VennDiagram::draw.pairwise.venn
这是默认格式化程序
body(myvenn)[[46]]
# wrapLab <- function(num) {
# stri = ""
# if (print.mode[1] == "percent") {
# stri <- paste(signif(num * 100/denom, digits = sigdigs),
# "%", sep = "")
# if (isTRUE(print.mode[2] == "raw")) {
# stri <- paste(stri, "\n(", num, ")", sep = "")
# }
# }
# if (print.mode[1] == "raw") {
# stri <- num
# if (isTRUE(print.mode[2] == "percent")) {
# stri <- paste(stri, "\n(", paste(signif(num * 100/denom,
# digits = sigdigs), "%)", sep = ""), sep = "")
# }
# }
# return(stri)
# }
让我们用prettyNum
调用替换它来添加逗号
body(myvenn)[[46]][[3]] <- quote(function(x) {
prettyNum(x ,big.mark=",",scientific=FALSE)
})
现在我们可以调用我们的函数版本
venn.plot <- myvenn(10000, 7000, 3000, c("First", "Second"), scaled = FALSE)
grid::grid.draw(venn.plot)
这是循环的另一种方式
venn.plot <- VennDiagram::draw.pairwise.venn(10000, 7000, 3000, c("First", "Second"), scaled = FALSE)
for(i in 1:length(venn.plot)){
if(!is.null(venn.plot[[i]][["label"]]) &&
!is.na(as.numeric(venn.plot[[i]][["label"]]))
) {
venn.plot[[i]][["label"]] <- prettyNum(venn.plot[[i]][["label"]], big.mark = ",")
}
}
Warning messages:
1: NAs introduced by coercion
2: NAs introduced by coercion
grid::grid.draw(venn.plot)