2013-02-08 158 views
1

我有這樣的數據:多維維恩圖

String[] a = {"a", "b", "c", "d"}; 
String[] b = {"c", "d"}; 
String[] c = {"b", "c"}; 

現在我需要這些列表的每個交叉點的圖形表示,大多這將導致這樣的維恩圖: http://manuals.bioinformatics.ucr.edu/_/rsrc/1353282523430/home/R_BioCondManual/r-bioc-temp/venn1.png?height=291&width=400

以我實現這些列表將主要包含1000多個條目,並且我將擁有10個以上的列表,因此良好的表示會創建一組字符串並將它們相交。 在我最簡單的情況下,這將導致

set_a = {"c"};  // in all three lists 
set_b = {"b", "d"}; // in two of three lists 
set_c = {"a"};  // in one of three lists 

另一個要求是現在的交集的大小應該是成正比的列表中的出現次數。所以set_a的尺寸應該比set_c大3倍。

是否有任何lib的要求?

+0

http://stackoverflow.com/questions/11697196/draw-venn-diagram-using-java – 2013-02-08 14:04:19

+0

也許setb是'set_b = {「b」,「d」};'? – user000001 2013-02-08 14:23:02

+0

@WernerVesterås我知道這個線程和wolfram alpha不太好,因爲我需要在線。 char4j也是一樣,維納圖也很可怕......我需要像圖片中的東西。 – reox 2013-02-08 15:48:49

回答

0

我覺得這個節目不想要的轉換:

// The input 
    String[][] a = { 
     {"a", "b", "c", "d"}, 
     {"c", "d"}, 
     {"b", "c"} 
    }; 

    System.out.println("Input: "+ Arrays.deepToString(a)); 

    // Convert the input to a Set of Sets (so that we can hangle it more easily 
    Set<Set<String>> input = new HashSet<Set<String>>(); 
    for (String[] s : a) { 
     input.add(new HashSet<String>(Arrays.asList(s))); 
    } 

    // The map is used for counting how many times each element appears 
    Map<String, Integer> count = new HashMap<String, Integer>(); 
    for (Set<String> s : input) { 
     for (String i : s) { 
      if (!count.containsKey(i)) { 
       count.put(i, 1); 
      } else { 
       count.put(i, count.get(i) + 1); 
      } 
     } 
    } 

    //Create the output structure 
    Set<String> output[] = new HashSet[a.length + 1]; 
    for (int i = 1; i < output.length; i++) { 
     output[i] = new HashSet<String>(); 
    } 

    // Fill the output structure according the map 
    for (String key : count.keySet()) { 
     output[count.get(key)].add(key); 
    } 

    // And print the output 
    for (int i = output.length - 1; i > 0; i--) { 
     System.out.println("Set_" + i + " = " + Arrays.toString(output[i].toArray())); 
    } 

輸出:

Input: [[a, b, c, d], [c, d], [b, c]] 
Set_3 = [c] 
Set_2 = [d, b] 
Set_1 = [a] 
+0

但沒有圖形表示。確實很容易創建集合,但是我怎樣才能從中生成圖表? – reox 2013-02-08 15:50:29