Mapping the Ebola outbreak in R

Overview of affected countries

The ebola outbreak caused 2536 deaths in Guinea, 4809 in Liberia and 3956 in Sierra Leone in 2014-2015. The number of suspected, probable and confirmed ebola cases in the three countries were 3804, 10675 and 14124, respectively. Data on the outbreak by district can be downloaded here:

Pre-processed files with the cumulative number of confirmed cases per month:

Pre-processed files with number of confirmed cases per week:

Shape files with borders for the three countries as well as for districts within countries can be downloaded here:

The interactive map below was created using the following R-code. The countries can be clicked to show the number of cases and ebola deaths.

Mapping the number of cases over time and district

The cumulative number of confirmed ebola cases based on the patient database was calculated by month and district within country. The result is shown below. But first the shapefiles need to be imported and merged with the cumulative number of cases.

# Import data
gin.cases<-read.csv("C:/Users/soren/Documents/omicron/hjemmeside/consula/ebola-outbreak/guinea1.csv",header=T)
gin.adm<-readOGR("C:/Users/soren/Documents/omicron/hjemmeside/consula/ebola-outbreak/GIN_admin_SHP/GIN.shp")
gin.outline<-readOGR("C:/Users/soren/Documents/omicron/hjemmeside/consula/ebola-outbreak/GIN_outline_SHP/GIN_outline.shp")
proj4string(gin.adm)<-CRS("+proj=longlat +datum=WGS84")
proj4string(gin.outline)<-CRS("+proj=longlat +datum=WGS84")
gin.adm.trans<-spTransform(gin.adm,osm())
gin.outline.trans<-spTransform(gin.outline,osm())

lib.cases<-read.csv("C:/Users/soren/Documents/omicron/hjemmeside/consula/ebola-outbreak/liberia1.csv",header=T)
lib.adm<-readOGR("C:/Users/soren/Documents/omicron/hjemmeside/consula/ebola-outbreak/LIB-level_1_SHP/LIB-level_1.shp")
lib.outline<-readOGR("C:/Users/soren/Documents/omicron/hjemmeside/consula/ebola-outbreak/LIB_outline_SHP/LIB_outline.shp")
proj4string(lib.adm)<-CRS("+proj=longlat +datum=WGS84")
proj4string(lib.outline)<-CRS("+proj=longlat +datum=WGS84")
lib.adm.trans<-spTransform(lib.adm,osm())
lib.outline.trans<-spTransform(lib.outline,osm())

sil.cases<-read.csv("C:/Users/soren/Documents/omicron/hjemmeside/consula/ebola-outbreak/sierra-leone1.csv",header=T)
sil.adm<-readOGR("C:/Users/soren/Documents/omicron/hjemmeside/consula/ebola-outbreak/SIL_admin_SHP/SIL.shp")
sil.outline<-readOGR("C:/Users/soren/Documents/omicron/hjemmeside/consula/ebola-outbreak/SIL_outline_SHP/SIL_outline.shp")
proj4string(sil.adm)<-CRS("+proj=longlat +datum=WGS84")
proj4string(sil.outline)<-CRS("+proj=longlat +datum=WGS84")
sil.adm.trans<-spTransform(sil.adm,osm())
sil.outline.trans<-spTransform(sil.outline,osm())

# Some processing
gin.adm.trans1<-fortify(gin.adm.trans)
gin.outline.trans1<-fortify(gin.outline.trans)
gin.adm.trans@data$ID<-rownames(gin.adm.trans@data)
gin.by.month.2<-merge(gin.adm.trans@data,gin.cases,by.x="ADM2",by.y="loc",all=TRUE)
gin.month1<-merge(gin.adm.trans1,gin.by.month.2,by.x="id",by.y="ID",all=TRUE)

lib.adm.trans1<-fortify(lib.adm.trans)
lib.outline.trans1<-fortify(lib.outline.trans)
lib.adm.trans@data$ADM2<-lib.adm.trans@data$ID
lib.adm.trans@data$ID<-rownames(lib.adm.trans@data)
lib.by.month.2<-merge(lib.adm.trans@data,lib.cases,by.x="ADM2",by.y="loc",all=TRUE)
lib.month1<-merge(lib.adm.trans1,lib.by.month.2,by.x="id",by.y="ID",all=TRUE)

sil.adm.trans1<-fortify(sil.adm.trans)
sil.outline.trans1<-fortify(sil.outline.trans)
sil.adm.trans@data$ID<-rownames(sil.adm.trans@data)
sil.by.month.2<-merge(sil.adm.trans@data,sil.cases,by.x="ADM2",by.y="loc",all=TRUE)
sil.month1<-merge(sil.adm.trans1,sil.by.month.2,by.x="id",by.y="ID",all=TRUE)

# Plotting
months<-c("Jan 2014","Feb 2014","Mar 2014","Apr 2014","May 2014","Jun 2014","Jul 2014","Aug 2014","Sep 2014","Oct 2014","Nov 2014",
"Dec 2014","Jan 2015","Feb 2015","Mar 2015","Apr 2015","May 2015","Jun 2015","Jul 2015","Aug 2015","Sep 2015","Oct 2015",
"Nov 2015","Dec 2015","Jan 2016")
mycol<-c("#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d")
thm<-theme(axis.text=element_blank(),axis.ticks=element_blank(),axis.title=element_blank(),legend.position="none")
ebola.map<-openmap(c(lat=13,lon=-16),c(lat=4,lon=-6.5),type="nps")
tit.loc<-data.frame(x=-1480000,y=550000)

for(jj in 1:25){

# Guinea
for(i in 1:dim(gin.month1)[1]){

if(gin.month1[i,24+jj]==0){gin.month1$Num[i]<-0}
if(gin.month1[i,24+jj]>0 & gin.month1[i,24+jj]<=10){gin.month1$Num[i]<-1}
if(gin.month1[i,24+jj]>10 & gin.month1[i,24+jj]<=50){gin.month1$Num[i]<-2}
if(gin.month1[i,24+jj]>50 & gin.month1[i,24+jj]<=100){gin.month1$Num[i]<-3}
if(gin.month1[i,24+jj]>100 & gin.month1[i,24+jj]<=250){gin.month1$Num[i]<-4}
if(gin.month1[i,24+jj]>250 & gin.month1[i,24+jj]<=500){gin.month1$Num[i]<-5}
if(gin.month1[i,24+jj]>500 & gin.month1[i,24+jj]<=750){gin.month1$Num[i]<-6}
if(gin.month1[i,24+jj]>750 & gin.month1[i,24+jj]<=1000){gin.month1$Num[i]<-7}
if(gin.month1[i,24+jj]>1000){gin.month1$Num[i]<-8}

}
gin.month1$Num.c<-as.factor(gin.month1$Num)

# Liberia
for(i in 1:dim(lib.month1)[1]){

if(lib.month1[i,11+jj]==0){lib.month1$Num[i]<-0}
if(lib.month1[i,11+jj]>0 & lib.month1[i,11+jj]<=10){lib.month1$Num[i]<-1}
if(lib.month1[i,11+jj]>10 & lib.month1[i,11+jj]<=50){lib.month1$Num[i]<-2}
if(lib.month1[i,11+jj]>50 & lib.month1[i,11+jj]<=100){lib.month1$Num[i]<-3}
if(lib.month1[i,11+jj]>100 & lib.month1[i,11+jj]<=250){lib.month1$Num[i]<-4}
if(lib.month1[i,11+jj]>250 & lib.month1[i,11+jj]<=500){lib.month1$Num[i]<-5}
if(lib.month1[i,11+jj]>500 & lib.month1[i,11+jj]<=750){lib.month1$Num[i]<-6}
if(lib.month1[i,11+jj]>750 & lib.month1[i,11+jj]<=1000){lib.month1$Num[i]<-7}
if(lib.month1[i,11+jj]>1000){lib.month1$Num[i]<-8}

}
lib.month1$Num.c<-as.factor(lib.month1$Num)

# Sierra Lione
for(i in 1:dim(sil.month1)[1]){

if(sil.month1[i,24+jj]==0){sil.month1$Num[i]<-0}
if(sil.month1[i,24+jj]>0 & sil.month1[i,24+jj]<=10){sil.month1$Num[i]<-1}
if(sil.month1[i,24+jj]>10 & sil.month1[i,24+jj]<=50){sil.month1$Num[i]<-2}
if(sil.month1[i,24+jj]>50 & sil.month1[i,24+jj]<=100){sil.month1$Num[i]<-3}
if(sil.month1[i,24+jj]>100 & sil.month1[i,24+jj]<=250){sil.month1$Num[i]<-4}
if(sil.month1[i,24+jj]>250 & sil.month1[i,24+jj]<=500){sil.month1$Num[i]<-5}
if(sil.month1[i,24+jj]>500 & sil.month1[i,24+jj]<=750){sil.month1$Num[i]<-6}
if(sil.month1[i,24+jj]>750 & sil.month1[i,24+jj]<=1000){sil.month1$Num[i]<-7}
if(sil.month1[i,24+jj]>1000){sil.month1$Num[i]<-8}

}
sil.month1$Num.c<-as.factor(sil.month1$Num)

p<-autoplot(ebola.map)+
geom_polygon(aes(x=long,y=lat,group=group,fill=Num.c),data=gin.month1)+geom_path(aes(x=long,y=lat,group=group),data=gin.month1,color='gray')+
geom_path(aes(x=long,y=lat,group=group),data=gin.outline.trans1,color='black',size=1)+
geom_polygon(aes(x=long,y=lat,group=group,fill=Num.c),data=lib.month1)+geom_path(aes(x=long,y=lat,group=group),data=lib.month1,color='gray')+
geom_path(aes(x=long,y=lat,group=group),data=lib.outline.trans1,color='black',size=1)+
geom_polygon(aes(x=long,y=lat,group=group,fill=Num.c),data=sil.month1)+geom_path(aes(x=long,y=lat,group=group),data=sil.month1,color='gray')+
geom_path(aes(x=long,y=lat,group=group),data=sil.outline.trans1,color='black',size=1)+
geom_text(x=tit.loc$x,y=tit.loc$y,label=paste(months[jj]),size=5,col='black',fontface="bold")+
scale_fill_manual(values=mycol)+thm

nam<-paste("p",jj,sep="")
assign(nam,p)
}

and now the results can be plotted