2012-02-03 11 views
6

私はvenneuler venn図の凡例を作成したいと思います。関数venneulerがコンソールに使用されている色を返すので、これは簡単です。色は0と1の間の値です。$ colorsに格納されている数値を凡例のfill引数を埋めるために使う方法を知りたいと思います。legend venn veneneulerの図

私はvenneulerから抽出した$ colorsとcolors()のインデックスを使ってこれを試みました。色()は区間の値でインデックス付けされていますが、私は何を望むかを示すためにこれを入れます。あなたはそれが色の文字列をRGBにy$colorsに数値を変換する方法を見ることができますplot.VennDiagramとそのデフォルトを熟読することにより

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

答えて

8

getAnywhere("plot.VennDiagram")でお試しください。

ここでは、色を(あなたの場合は)処理した2ビットのコードを、変換を行う1つの関数にまとめました。完璧だ、おそらく改善される可能性が伝説のポジショニングが、それは別の問題だ...

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

enter image description here

+0

オブライアン。 –

+0

私は 'id < - 一致(名前(y $色、LAB))' の代わりに使用しました –