<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>韦恩图 on 格物堂</title><link>https://gewutang.cn/tags/%E9%9F%A6%E6%81%A9%E5%9B%BE/</link><description>Recent content in 韦恩图 on 格物堂</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><lastBuildDate>Sat, 27 Aug 2011 00:00:00 +0000</lastBuildDate><atom:link href="https://gewutang.cn/tags/%E9%9F%A6%E6%81%A9%E5%9B%BE/index.xml" rel="self" type="application/rss+xml"/><item><title>R语言绘制维恩图</title><link>https://gewutang.cn/2011/08/27/venn/</link><pubDate>Sat, 27 Aug 2011 00:00:00 +0000</pubDate><guid>https://gewutang.cn/2011/08/27/venn/</guid><description>&lt;p&gt;很久之前整理的关于R绘制维恩图的资料，虽然，用R绘制维恩图并不是很常见，还是记下一笔，以备需要者参考。&lt;/p&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;# Gplots包&#10;library(gplots)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## &#10;## 载入程序包：'gplots'&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## The following object is masked from 'package:stats':&#10;## &#10;## lowess&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;A&amp;lt;- 1:20&#10;B&amp;lt;- 1:20&#10;C&amp;lt;- 2:20&#10;D&amp;lt;- 3:21&#10;&#10;input&amp;lt;-list(A,B,C,D)&#10;input&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## [[1]]&#10;## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20&#10;## &#10;## [[2]]&#10;## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20&#10;## &#10;## [[3]]&#10;## [1] 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20&#10;## &#10;## [[4]]&#10;## [1] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;venn(input)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-1.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;A&amp;lt;- as.logical(rbinom(100, 1, 0.2))&#10;B&amp;lt;- as.logical(rbinom(100, 1, 0.7))&#10;C&amp;lt;- as.logical(rbinom(100, 1, 0.2))&#10;D&amp;lt;- as.logical(rbinom(100, 1, 0.1))&#10;&#10;input&amp;lt;-data.frame(A,B,C,D)&#10;venn(input)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-2.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;tmp &amp;lt;- venn(input, simplify=TRUE)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## Warning in drawVennDiagram(data = counts, small = small, showSetLogicLabel = showSetLogicLabel, : Not shown: 0101 contains 2&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-3.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;tmp&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## num A B C D&#10;## 0000 0 0 0 0 0&#10;## 0001 1 0 0 0 1&#10;## 0010 4 0 0 1 0&#10;## 0011 0 0 0 1 1&#10;## 0100 36 0 1 0 0&#10;## 0101 2 0 1 0 1&#10;## 0110 6 0 1 1 0&#10;## 0111 1 0 1 1 1&#10;## 1000 5 1 0 0 0&#10;## 1001 0 1 0 0 1&#10;## 1010 0 1 0 1 0&#10;## 1011 1 1 0 1 1&#10;## 1100 15 1 1 0 0&#10;## 1101 1 1 1 0 1&#10;## 1110 6 1 1 1 0&#10;## 1111 1 1 1 1 1&#10;## attr(,&amp;quot;intersections&amp;quot;)&#10;## attr(,&amp;quot;intersections&amp;quot;)$A&#10;## [1] &amp;quot;18&amp;quot; &amp;quot;29&amp;quot; &amp;quot;32&amp;quot; &amp;quot;54&amp;quot; &amp;quot;58&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$B&#10;## [1] &amp;quot;12&amp;quot; &amp;quot;14&amp;quot; &amp;quot;19&amp;quot; &amp;quot;22&amp;quot; &amp;quot;28&amp;quot; &amp;quot;30&amp;quot; &amp;quot;34&amp;quot; &amp;quot;36&amp;quot; &amp;quot;40&amp;quot; &amp;quot;43&amp;quot; &amp;quot;45&amp;quot; &amp;quot;46&amp;quot; &#10;## [13] &amp;quot;51&amp;quot; &amp;quot;52&amp;quot; &amp;quot;53&amp;quot; &amp;quot;57&amp;quot; &amp;quot;60&amp;quot; &amp;quot;66&amp;quot; &amp;quot;67&amp;quot; &amp;quot;68&amp;quot; &amp;quot;69&amp;quot; &amp;quot;70&amp;quot; &amp;quot;73&amp;quot; &amp;quot;75&amp;quot; &#10;## [25] &amp;quot;76&amp;quot; &amp;quot;77&amp;quot; &amp;quot;78&amp;quot; &amp;quot;80&amp;quot; &amp;quot;81&amp;quot; &amp;quot;87&amp;quot; &amp;quot;88&amp;quot; &amp;quot;89&amp;quot; &amp;quot;92&amp;quot; &amp;quot;94&amp;quot; &amp;quot;98&amp;quot; &amp;quot;100&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$C&#10;## [1] &amp;quot;6&amp;quot; &amp;quot;10&amp;quot; &amp;quot;33&amp;quot; &amp;quot;84&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$D&#10;## [1] &amp;quot;79&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$`A:B`&#10;## [1] &amp;quot;2&amp;quot; &amp;quot;5&amp;quot; &amp;quot;9&amp;quot; &amp;quot;13&amp;quot; &amp;quot;17&amp;quot; &amp;quot;21&amp;quot; &amp;quot;25&amp;quot; &amp;quot;26&amp;quot; &amp;quot;27&amp;quot; &amp;quot;38&amp;quot; &amp;quot;39&amp;quot; &amp;quot;44&amp;quot; &amp;quot;49&amp;quot; &amp;quot;50&amp;quot; &amp;quot;56&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$`B:C`&#10;## [1] &amp;quot;20&amp;quot; &amp;quot;71&amp;quot; &amp;quot;72&amp;quot; &amp;quot;82&amp;quot; &amp;quot;83&amp;quot; &amp;quot;97&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$`B:D`&#10;## [1] &amp;quot;62&amp;quot; &amp;quot;63&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$`A:B:C`&#10;## [1] &amp;quot;3&amp;quot; &amp;quot;11&amp;quot; &amp;quot;47&amp;quot; &amp;quot;74&amp;quot; &amp;quot;85&amp;quot; &amp;quot;95&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$`A:B:D`&#10;## [1] &amp;quot;96&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$`A:C:D`&#10;## [1] &amp;quot;7&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$`B:C:D`&#10;## [1] &amp;quot;23&amp;quot;&#10;## &#10;## attr(,&amp;quot;intersections&amp;quot;)$`A:B:C:D`&#10;## [1] &amp;quot;37&amp;quot;&#10;## &#10;## attr(,&amp;quot;class&amp;quot;)&#10;## [1] &amp;quot;venn&amp;quot;&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;venn(input, showSetLogicLabel=TRUE)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-4.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;# asbio包&#10;library(asbio)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：tcltk&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;Venn(A=.3,B=.2,AandB=.06)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-5.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;# limma包&#10;# install.packages(&amp;quot;BiocManager&amp;quot;)&#10;# BiocManager::install(&amp;quot;limma&amp;quot;)&#10;library(limma)&#10;Y &amp;lt;- matrix(rnorm(100*6),100,6)&#10;Y[1:10,3:4] &amp;lt;- Y[1:10,3:4]+3&#10;Y[1:20,5:6] &amp;lt;- Y[1:20,5:6]+3&#10;design &amp;lt;- cbind(1,c(0,0,1,1,0,0),c(0,0,0,0,1,1))&#10;fit &amp;lt;- eBayes(lmFit(Y,design))&#10;results &amp;lt;- decideTests(fit)&#10;a &amp;lt;- vennCounts(results)&#10;print(a)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## x1 x2 x3 Counts&#10;## 1 0 0 0 88&#10;## 2 0 0 1 8&#10;## 3 0 1 0 0&#10;## 4 0 1 1 4&#10;## 5 1 0 0 0&#10;## 6 1 0 1 0&#10;## 7 1 1 0 0&#10;## 8 1 1 1 0&#10;## attr(,&amp;quot;class&amp;quot;)&#10;## [1] &amp;quot;VennCounts&amp;quot;&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;vennDiagram(a)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-6.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;vennDiagram(results,include=c(&amp;quot;up&amp;quot;,&amp;quot;down&amp;quot;),counts.col=c(&amp;quot;red&amp;quot;,&amp;quot;green&amp;quot;))&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-7.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;# venneuler包&#10;&#10;library(venneuler)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：rJava&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;vd &amp;lt;- venneuler(c(A=0.3, B=0.3, C=1.1, &amp;quot;A&amp;amp;B&amp;quot;=0.1, &amp;quot;A&amp;amp;C&amp;quot;=0.2, &amp;quot;B&amp;amp;C&amp;quot;=0.1 ,&amp;quot;A&amp;amp;B&amp;amp;C&amp;quot;=0.1))&#10;&#10;plot(vd)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-8.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;m &amp;lt;- data.frame(elements=c(&amp;quot;1&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;2&amp;quot;,&amp;quot;3&amp;quot;),sets=c(&amp;quot;A&amp;quot;,&amp;quot;A&amp;quot;,&amp;quot;B&amp;quot;,&amp;quot;C&amp;quot;,&amp;quot;C&amp;quot;))&#10; &#10;v &amp;lt;- venneuler(m)&#10;&#10;plot(v)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-9.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;m &amp;lt;- as.matrix(data.frame(A=c(1.5, 0.2, 0.4, 0, 0),B=c(0, 0.2, 0, 1, 0), C=c(0, 0, 0.3, 0, 1)))&#10;&#10;v &amp;lt;- venneuler(m &amp;gt; 0)&#10;&#10;plot(v)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-10.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;v &amp;lt;- venneuler(m)&#10;&#10;plot(v)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-11.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;# Vennerable包&#10;&#10;# BiocManager::install(&amp;quot;graph&amp;quot;)&#10;# BiocManager::install(&amp;quot;RBGL&amp;quot;)&#10;# BiocManager::install(&amp;quot;reshape&amp;quot;)&#10;# install.packages(&amp;quot;Vennerable&amp;quot;, repos=&amp;quot;http://R-Forge.R-project.org&amp;quot;)&#10;&#10;library(Vennerable)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：graph&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：BiocGenerics&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：generics&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## &#10;## 载入程序包：'generics'&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## The following objects are masked from 'package:base':&#10;## &#10;## as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,&#10;## setequal, union&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## &#10;## 载入程序包：'BiocGenerics'&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## The following objects are masked from 'package:rJava':&#10;## &#10;## anyDuplicated, duplicated, unique&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## The following object is masked from 'package:limma':&#10;## &#10;## plotMA&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## The following objects are masked from 'package:stats':&#10;## &#10;## IQR, mad, sd, var, xtabs&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## The following objects are masked from 'package:base':&#10;## &#10;## anyDuplicated, aperm, append, as.data.frame, basename, cbind,&#10;## colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,&#10;## get, grep, grepl, is.unsorted, lapply, Map, mapply, match, mget,&#10;## order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,&#10;## rbind, Reduce, rownames, sapply, saveRDS, table, tapply, unique,&#10;## unsplit, which.max, which.min&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：RBGL&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：grid&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：lattice&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：RColorBrewer&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：reshape&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：gtools&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 载入需要的程序包：xtable&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## &#10;## 载入程序包：'Vennerable'&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## The following object is masked from 'package:asbio':&#10;## &#10;## Venn&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;Venn(n=3)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## A Venn object on 3 sets named&#10;## 1,2,3 &#10;## 000 100 010 110 001 101 011 111 &#10;## 1 1 1 1 1 1 1 1&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;plot(Venn(n=3))&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-12.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;data(StemCell)&#10;w &amp;lt;- Venn(Sets=StemCell[1:2])&#10;Weights(w)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code&gt;## 00 10 01 11 &#10;## 0 219 875 404&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;plot(w)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-13.png" width="672" /&gt;&#10;&lt;pre&gt;&lt;code class="language-r"&gt;Weights(w) &amp;lt;- 1:4&#10;plot(w)&#10;&lt;/code&gt;&lt;/pre&gt;&#10;&lt;img src="https://gewutang.cn/2011/08/27/venn/index_files/figure-html/unnamed-chunk-1-14.png" width="672" /&gt;&#10;</description></item></channel></rss>