> source("http://bioconductor.org/biocLite.R")
> biocLite("limma")
> library(limma)
> hsb2<-read.table("http://www.ats.ucla.edu/stat/R/notes/hsb2.csv", sep=',', header=T)
> attach(hsb2)
> hw<-(write>=60)
> hm<-(math >=60)
> hr<-(read >=60)
> c3<-cbind(hw, hm, hr)
> a <- vennCounts(c3); a
hw hm hr Counts
[1,] 0 0 0 113
[2,] 0 0 1 18
[3,] 0 1 0 8
[4,] 0 1 1 8
[5,] 1 0 0 12
[6,] 1 0 1 8
[7,] 1 1 0 11
[8,] 1 1 1 22
attr(,"class")
[1] "VennCounts"
> vennDiagram(a, include = "both", names = c("High Writing", "High Math", "High Reading"),
cex = 1, counts.col = "red")
LIMMA绘制文氏图 从上面的剧本我们可以知道,LIMMA在绘制文氏图的时候,先是对数据转换成bool范例的矩阵, 尔后举办分组计数,分组就包罗所有大概的组合,得出数字后画图。
在利用LIMMA画图的时候,我们会以为步调太多,gplots提供了一步的办理方案,你提供list可能data.frame数据,就可以了。
> library(gplots)
> ##
> ## Example using a list of item names belonging to the
> ## specified group.
> ##
>
> ## construct some fake gene names..
> oneName <- function() paste(sample(LETTERS,5,replace=TRUE),collapse="")
> geneNames <- replicate(1000, oneName())
>
> ##
> GroupA <- sample(geneNames, 400, replace=FALSE)
> GroupB <- sample(geneNames, 750, replace=FALSE)
> GroupC <- sample(geneNames, 250, replace=FALSE)
> GroupD <- sample(geneNames, 300, replace=FALSE)
> input <-list(GroupA,GroupB,GroupC,GroupD)
> venn(input)
|
gplot绘制文氏图
> ##
> ## Example using a list of item indexes belonging to the
> ## specified group.
> ##
> GroupA.i <- which(geneNames %in% GroupA)
> GroupB.i <- which(geneNames %in% GroupB)
> GroupC.i <- which(geneNames %in% GroupC)
> GroupD.i <- which(geneNames %in% GroupD)
> input.i <-list(A=GroupA.i,B=GroupB.i,C=GroupC.i,D=GroupD.i)
> venn(input.i)
|
gplot绘制文氏图
> ##
> ## Example using a data frame of indicator ('f'lag) columns
> ##
> GroupA.f <- geneNames %in% GroupA
> GroupB.f <- geneNames %in% GroupB
> GroupC.f <- geneNames %in% GroupC
> GroupD.f <- geneNames %in% GroupD
> input.df <- data.frame(A=GroupA.f,B=GroupB.f,C=GroupC.f,D=GroupD.f)
> venn(input.df)
|
gplot绘制文氏图
可是,上面两种要领绘制出来的图都不能是彩色的。这不得不说是一个很大的缺憾。厥后又呈现两个文氏图的绘制东西包,别离是venneuler以及VennDiagram。先容它们的文献别离是:《Exact and Approximate Area-proportional Circular Venn and Euler Diagrams》– Leland Wilkinson, 以及《VennDiagram: a package for the generation of highly-customizable Venn and Euler diagrams in R》– Hanbo Chen, Paul C Boutros。在后者的文献中,有对现有文氏图绘制软件的较量表格。这里我主要总结三点:
|
limma::vennDiagram |
gplots::venn |
venneuler |
VennDiagram |
彩色 |
否 |
否 |
是 |
是 |
输入 |
R object |
Lists |
combinations |
Lists |
较大组数 |
3 |
5 |
3 |
4 |
> library("venneuler")
> m <- 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)))
> # without weights
> v <- venneuler(m > 0)
> plot(v)
> # with weights
> v <- venneuler(m)
> plot(v)
|
#p#分页标题#e#
venneuler绘制文氏图
venneuler绘制文氏图
利用VennDiagram的话,用户本身可以配置的参数更多,可是却显得不易把握。假如能再提供一些气势气魄就好了。
> library(VennDiagram)
> names(input)<-c("A","B","C","D")
> venn.diagram(input,"VennDiagram.venn.png",
col = "transparent",fill = c("cornflowerblue", "green", "yellow", "darkorchid1"),alpha = 0.50,
label.col = c("orange", "white", "darkorchid4", "white", "white", "white", "white", "white",
"darkblue", "white", "white", "white", "white", "darkgreen", "white"),
cat.col = c("darkblue", "darkgreen", "orange", "darkorchid4"),)
|
|