我有些麻烦/我需要绘制维恩图并一起打印重量值和百分比。现在我写这段代码:
library(Vennerable)
> areas
00 01 10 11
38596 6024 40696 8971
VennSet <- Venn(SetNames = category, Weight = areas)
VennList <- compute.Venn(VennSet, doWeights = TRUE)
gp <- VennThemes(VennList)
plot(VennList, gpList=gp, show = list(FaceText = c("signature", "weight"), DarkMatter = TRUE))
结果:
然后我想改变最后一行的值。
pcentFun <- function(x) {
100 * (x /sum(x))
}
areasPcent <- round(pcentFun(areas), digits=2)
VennList@FaceLabels$Signature <- paste(areasPcent, "%", sep="")
结果:
我已经打印了百分比,但是减轻了重量。 这是对象的结构:
> str(VennList)
Formal class 'VennDrawing' [package "Vennerable"] with 11 slots
..@ universe : num [1:2, 1:2] -209 152 -150 150
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "x" "y"
..@ SetLabels :'data.frame': 2 obs. of 5 variables:
.. ..$ Label: chr [1:2] "Glia.LAM.mf_min.bound" "Glia.HP1.mf_min.bound"
.. ..$ x : num [1:2] -54.2 54.2
.. ..$ y : num [1:2] 128.3 71.6
.. ..$ hjust:Class 'AsIs' chr [1:2] "center" "center"
.. ..$ vjust: chr [1:2] "bottom" "bottom"
..@ FaceLabels :'data.frame': 4 obs. of 6 variables:
.. ..$ FaceName : chr [1:4] "01" "10" "11" "DarkMatter"
.. ..$ Signature: chr [1:4] "40.93%" "6.39%" "43.16%" "9.51%"
.. ..$ x : num [1:4] 97.4 -97.4 28.3 123.3
.. ..$ y : num [1:4] 0.00 1.19e-14 4.23e-15 1.26e+02
.. ..$ hjust : chr [1:4] "centre" "centre" "centre" "right"
.. ..$ vjust : chr [1:4] "centre" "centre" "centre" "top"
..@ setList :List of 2
.. ..$ Set1: chr [1:2] "i24|i23|1" "i23|i24|1"
.. ..$ Set2: chr [1:2] "i24|i23|2" "i23|i24|2"
..@ nodeList :List of 2
.. ..$ i23: num [1, 1:2] 50.9 69
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr "i23"
.. .. .. ..$ : chr [1:2] "x" "y"
.. ..$ i24: num [1, 1:2] 50.9 -69
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr "i24"
.. .. .. ..$ : chr [1:2] "x" "y"
..@ recentChanges : chr [1:2] "c11|i24|1" "i24|i23|1"
..@ edgeList :List of 4
.. ..$ i24|i23|1:Formal class 'VDedgeSector' [package "Vennerable"] with 9 slots
.. .. .. ..@ radius : num 126
.. .. .. ..@ fromTheta: num 5.7
.. .. .. ..@ toTheta : num 0.581
.. .. .. ..@ centre : num [1:2] -54.2 0
.. .. .. ..@ hand : num 1
.. .. .. ..@ from : chr "i24"
.. .. .. ..@ to : chr "i23"
.. .. .. ..@ visible : logi TRUE
.. .. .. ..@ bb : num [1:2, 1:2] -179.9 71.5 -125.7 125.7
.. ..$ i24|i23|2:Formal class 'VDedgeSector' [package "Vennerable"] with 9 slots
.. .. .. ..@ radius : num 69.1
.. .. .. ..@ fromTheta: num 4.66
.. .. .. ..@ toTheta : num 1.62
.. .. .. ..@ centre : num [1:2] 54.2 0
.. .. .. ..@ hand : num 1
.. .. .. ..@ from : chr "i24"
.. .. .. ..@ to : chr "i23"
.. .. .. ..@ visible : logi TRUE
.. .. .. ..@ bb : num [1:2, 1:2] -14.9 123.3 -69.1 69.1
.. ..$ i23|i24|1:Formal class 'VDedgeSector' [package "Vennerable"] with 9 slots
.. .. .. ..@ radius : num 126
.. .. .. ..@ fromTheta: num 0.581
.. .. .. ..@ toTheta : num -0.581
.. .. .. ..@ centre : num [1:2] -54.2 0
.. .. .. ..@ hand : num 1
.. .. .. ..@ from : chr "i23"
.. .. .. ..@ to : chr "i24"
.. .. .. ..@ visible : logi TRUE
.. .. .. ..@ bb : num [1:2, 1:2] -179.9 71.5 -125.7 125.7
.. ..$ i23|i24|2:Formal class 'VDedgeSector' [package "Vennerable"] with 9 slots
.. .. .. ..@ radius : num 69.1
.. .. .. ..@ fromTheta: num 1.62
.. .. .. ..@ toTheta : num -1.62
.. .. .. ..@ centre : num [1:2] 54.2 0
.. .. .. ..@ hand : num 1
.. .. .. ..@ from : chr "i23"
.. .. .. ..@ to : chr "i24"
.. .. .. ..@ visible : logi TRUE
.. .. .. ..@ bb : num [1:2, 1:2] -14.9 123.3 -69.1 69.1
..@ faceList :List of 4
.. ..$ DarkMatter: chr [1:2] "-i24|i23|1" "-i23|i24|2"
.. ..$ 11 : chr [1:2] "i24|i23|2" "i23|i24|1"
.. ..$ 10 : chr [1:2] "i24|i23|1" "-i24|i23|2"
.. ..$ 01 : chr [1:2] "i23|i24|2" "-i23|i24|1"
..@ faceSignature :List of 4
.. ..$ DarkMatter: chr "DarkMatter"
.. ..$ 11 : chr "11"
.. ..$ 10 : chr "10"
.. ..$ 01 : chr "01"
..@ IndicatorWeight : num [1:4, 1:3] 0 1 0 1 0 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:4] "00" "10" "01" "11"
.. .. ..$ : chr [1:3] "Glia.LAM.mf_min.bound" "Glia.HP1.mf_min.bound" ".Weight"
..@ IntersectionSets: list()
及其输出
> VennList
A Venn object on 2 sets named
Glia.LAM.mf_min.bound,Glia.HP1.mf_min.bound
00 10 01 11
38596 40696 6024 8971
from to type npoints centre hand
i24|i23|1 i24 i23 VDedgeSector NA -54.2116651664673,0 1
i24|i23|2 i24 i23 VDedgeSector NA 54.2116651664673,0 1
i23|i24|1 i23 i24 VDedgeSector NA -54.2116651664673,0 1
i23|i24|2 i23 i24 VDedgeSector NA 54.2116651664673,0 1
X1 X2
i23 50.89514 69.00766
i24 50.89514 -69.00766
faces
DarkMatter -i24|i23|1;-i23|i24|2
11 i24|i23|2;i23|i24|1
10 i24|i23|1;-i24|i23|2
01 i23|i24|2;-i23|i24|1
sig
DarkMatter DarkMatter
11 11
10 10
01 01
paste.face..collapse.......
Set1 i24|i23|1;i23|i24|1
Set2 i24|i23|2;i23|i24|2
谁知道如何输出重量和百分比?
答案 0 :(得分:0)
这不是我想要的。但也有权存在。
areasPcent <- round(pcentFun(areas), digits=2)
VennSet <- Venn(SetNames = category, Weight = areas)
VennList <- compute.Venn(VennSet, doWeights = TRUE)
VennList_pc <- VennList
for (i in c(1:length(areasPcent))) {
position <- grep(names(areasPcent)[i], VennList_pc@FaceLabels$Signature)
VennList_pc@FaceLabels$Signature[position] <- paste(areasPcent[i], "%", sep="")
}
gp <- VennThemes(VennList)
pdf(file=file.path(paste("Venn Diagram between ", v2, " from ", v1, ".pdf", sep="")), width=8, height=12.76)
par(mfrow=c(1, 2))
par(mai=c(0.7, 0.7, 0.7, 0.5))
rowNumberMakevp <<- 1
plot(VennList, gpList=gp)
rowNumberMakevp <<- 2
plot(VennList_pc, gpList=gp, show = list(FaceText = c("signature"), DarkMatter = TRUE))
dev.off()
的多图表解决方案
答案 1 :(得分:0)
尽管这个问题是在几年前提出的,但我认为最好分享对我有用的答案。实际上,我发现了一种更简单的方法(在areas
和areasPcent
之间使用换行符),如下所示:
VennList@FaceLabels$Signature <- paste0(areas, "\n", areasPcent, "%")
plot(VennList, gpList=gp, show = list(FaceText = c("signature"), DarkMatter = TRUE))
请注意,您只需要在"signature"
中显示FaceText
。
希望有帮助。