summaryrefslogtreecommitdiffstats
path: root/R Scripts/plot-data-prep.R
diff options
context:
space:
mode:
Diffstat (limited to 'R Scripts/plot-data-prep.R')
-rw-r--r--R Scripts/plot-data-prep.R20
1 files changed, 11 insertions, 9 deletions
diff --git a/R Scripts/plot-data-prep.R b/R Scripts/plot-data-prep.R
index 937512a..27c2416 100644
--- a/R Scripts/plot-data-prep.R
+++ b/R Scripts/plot-data-prep.R
@@ -8,15 +8,15 @@ library(gridExtra)
# create bipartite graph
edges = c(1,6,
1,7,
- 1,10,
+ 1,9,
2,8,
3,7,
3,8,
- 3,10,
+ 3,9,
4,7,
4,8,
5,6,
- 5,9)
+ 5,10)
g = graph.bipartite(c(rep(T,5),rep(F,5)),edges)
par(mfrow=c(1,3), mar=c(1,1,1,1))
@@ -41,7 +41,7 @@ plot(g, layout=layout[,2:1], vertex.color=cols,edge.color='black',
# (C) unipartite person-person graph
par(mar=rep(1,4))
g2 = bipartite.projection(g)$proj1
-layout.g2 = matrix(c(0,.33,-.75,-.33,0,-1,0,1,.75,-.33),ncol=2,byrow=T)
+layout.g2 = matrix(c(0,.33,-.75,-.33,0,-1,.75,-.33,0,1),ncol=2,byrow=T)
plot(g2, vertex.color='#1f78b4', edge.color='black',layout=layout.g2,rescale=F,
vertex.frame.color=NA,vertex.size=30,vertex.label=toupper(letters[1:5]),
vertex.label.color='white',vertex.label.family='sans')
@@ -50,10 +50,11 @@ plot(g2, vertex.color='#1f78b4', edge.color='black',layout=layout.g2,rescale=F,
##############################################################################
#### Hawkes Process Diagram
layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow = TRUE))
+par(mar=c(1,1,1,1))
vics = data.frame(IC = toupper(letters[1:5]),
- Victim = c(T,F,F,F,T),
- Day = c(2,NA,NA,NA,4))
+ Victim = c('TRUE','FALSE','FALSE','TRUE','FALSE'),
+ Day = c(2,NA,NA,4,NA))
colnames(vics) = c('Identity Code (IC)','Victim','Infection Date')
# A
@@ -78,7 +79,7 @@ rate = function(x){
print(x)
r = rep(base+0.3,length(x))
for (time in times){
- r[x>=time] = r[x>=time] + 1.5*exp((time-x[x>=time])/2)
+ r[x>=time] = r[x>=time] + 1.5*exp((time-x[x>=time])/2.5)
}
return(r)
}
@@ -86,7 +87,7 @@ rate = function(x){
tmin = 1
tmax = 6
n = 1000
-plot(rate,from=tmin,to=tmax,ylim=c(0,15),lwd=0,bty='l',col='white',
+plot(rate,from=tmin,to=tmax,ylim=c(0,13),lwd=0,bty='l',col='white',
yaxt='n',xlab='Date',ylab='Infection Rate')
for(i in 1:vcount(g2)){
base <<- 3*(5-i)
@@ -98,5 +99,6 @@ for(i in 1:vcount(g2)){
polygon(xs,ys,col='#1f78b4',border=NA)
}
axis(2, at=seq(0.3,12.3,3), lab=toupper(letters[seq(5,1,-1)]), tick=F, las=T,lwd=0)
-
+polygon(c(1.98,1.98,2.02,2.02),c(12,14,14,12),col='#e41a1c',border=NA)
+polygon(c(3.98,3.98,4.02,4.02),c(3,5,5,3),col='#e41a1c',border=NA)