-
Notifications
You must be signed in to change notification settings - Fork 0
/
donutplot_fig.R
105 lines (92 loc) · 3.9 KB
/
donutplot_fig.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
##############################################################################/
##############################################################################/
#Code for the "donut" plot
##############################################################################/
##############################################################################/
#this code was written by Christophe Plantamp
#loading the packages and data necessary for the analysis
source("dataloading.R")
##############################################################################/
#preparing the dataset####
##############################################################################/
data<-data_pays[,c(1,2,6)]
divCoex<-numeric(dim(data)[1])
Modal<-levels(data$coexistence_pays)
Number<-c(1,0,2,1,2,1,3,2)
Monitoring<-data.frame(Official=numeric(dim(data)[1]),
Private=numeric(dim(data)[1]),
Research=numeric(dim(data)[1]))
for (i in 1:length(Modal)) {
divCoex[data$coexistence_pays==Modal[i]]<-Number[i]
}
data<-cbind(data,divCoex)
AA=xyTable(data$divCoex,data$nb_bioagr_surv)
#removing zero
AA$x<-AA$x[-c(1:2,9)]
AA$y<-AA$y[-c(1:2,9)]
AA$number<-AA$number[-c(1:2,9)]
#counting the number for each 'pest categories' x 'RMS in country categories'
Count_coex<-data.frame(x=numeric(0),y=numeric(0),
NA_NA_academic=character(0),
NA_NA_NA=character(0),
NA_private_academic=character(0),
NA_private_NA=character(0),
public_NA_academic=character(0),
public_NA_NA=character(0),
public_private_academic=character(0),
public_private_NA=character(0))
Titre<-colnames(Count_coex)
for(i in 1:3){
for(j in 1:3){
EXTRACT<-data[data$divCoex==i & data$nb_bioagr_surv==j,]
Count_coex<-rbind(Count_coex,(c(i,j,table(EXTRACT$coexistence_pays))))
}
}
colnames(Count_coex)<-Titre
Prop<-Count_coex[,c(1,2,3,8,6,7,5,10,9)]
colnames(Prop)<-c("x","y","Academic","Governmental","Private",
"Academic\nGovernmental","Academic\nPrivate",
"Governmental\nPrivate",
"Academic\nGovernmental\nPrivate")
##############################################################################/
#Figure 5D: Donut plot####
##############################################################################/
#setting a color palette
thecol<-brewer.pal(7,"Dark2")[7:1]
#here comes the plotting
def.par<-par(no.readonly=TRUE)
layout(cbind(1,2),widths=c(9,3))
op<-par(mar=c(6.5,6.5,1,0.5) + 0.1,xpd=TRUE)
plot(AA$x,AA$y,pch=16,col="white",xlim=c(0.5,3.2),ylim=c(0.5,3.5),
axes=FALSE,ann=FALSE,
xaxp=c(1,3,2),yaxp=c(1,3,2),xaxt="n",yaxt="n",bty="n",cex.lab=1.2,
font.lab=2,asp=1)
title(main=NULL,
xlab="Number of RMS\ncategories in the country",
cex.lab=1.5,line=4.5,font.lab=2,xpd=NA)
title(main=NULL,ylab="Number of surveyed\nbioagressor types in the country",
cex.lab=1.5,
line=3,font.lab=2,xpd=NA)
box(bty="l",lwd=4)
axis(1,at=1:3,labels=1:3,lwd=4,font=2,cex.axis=1.5)
axis(2,at=1:3,labels=1:3,lwd=4,las=1,font=2,cex.axis=1.5)
rayon<-sqrt(AA$number)
for (i in 1:nrow(Prop)){
floating.pie(Prop[i,1],Prop[i,2],x=as.numeric(Prop[i,3:9])+1e-7,
col=thecol,radius=rayon[i]*0.1,border=F)
draw.circle(Prop[i,1],Prop[i,2],col="white",radius=rayon[i]*0.1-0.07,
border=F)
}
text(AA$x,AA$y,AA$number,font=2,cex=1.3)
par(mar=c(6.1,0.5,0,0.1))
plot.new()
legend('topleft',legend=colnames(Prop)[c(5,3,4,8,6,7,9)],
border="transparent",pch=15,
col=thecol,bg=thecol,bty="n",horiz=FALSE,cex=0.9,pt.cex=1.4,
x.intersp=1.2,y.intersp=3.3,box.col="transparent")
text(0.5,1.02,labels="NRML",font=2)
par(op)
par(def.par)
##############################################################################/
#END
##############################################################################/