2017-03-29 3 views
1

では、Vennダイアグラム上のカンマ区切り記号を千単位に追加する方法があります。Vennダイアグラムにコンマ区切りを追加する方法

venn.plot <- VennDiagram::draw.pairwise.venn(10000, 7000, 3000, c("First", "Second"), scaled = FALSE) 

grid::grid.draw(venn.plot) 

結果のグラフは次のようになります。それは、この機能のように見えない

enter image description here

答えて

2

はそれを行うために設計されました。本当にこの機能を使用したい場合は、ラベルに使用するデフォルトの書式設定コードを置き換えるために「ハックする」ことができます。コードの特定の「行」を編集しているので、このメソッドは非常に壊れやすいことに注意してください。最初の関数のコピー

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) 
# } 

はのは、コンマ

body(myvenn)[[46]][[3]] <- quote(function(x) { 
    prettyNum(x ,big.mark=",",scientific=FALSE) 
}) 

を追加するprettyNumを呼び出してそのに代わっだ作りますの機能

venn.plot <- myvenn(10000, 7000, 3000, c("First", "Second"), scaled = FALSE) 
grid::grid.draw(venn.plot) 

enter image description here

1

また、アイテムを手動で編集することもできます。ここで

venn.plot[[5]][["label"]] <- "7,000" 
venn.plot[[6]][["label"]] <- "4,000" 
venn.plot[[7]][["label"]] <- "3,000" 

grid::grid.draw(venn.plot) 

enter image description here

0

ループ

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) 
と別の方法である
関連する問題