Last active
August 29, 2015 14:07
-
-
Save HughSt/a89e2a7d67f30e305e04 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(maptools) | |
library(RColorBrewer) | |
ShehiaShp<-readShapeSpatial("Data/ZnzPolyIncWGS1984.shp",proj4string=CRS("+proj=longlat")) | |
# Import case numbers by Shehia using different travel assumptions | |
Shehia_Inc_Trav<-read.csv("Data/Shehia_Inc_Travel.csv") | |
# Generate cats for colors | |
cols <- brewer.pal(10, "RdBu")[10:1] | |
# Calculate incidence | |
# Merge case data to shapefile | |
# First rename some shehias in the Incidence file to match the shapefile | |
Shehia_Inc_Trav$Shehia<-as.character(Shehia_Inc_Trav$Shehia) | |
Shehia_Inc_Trav$Shehia[Shehia_Inc_Trav$Shehia=="Mbuzini"]<-"Mbuzini_West" | |
Shehia_Inc_Trav$Shehia[Shehia_Inc_Trav$Shehia=="Ng'ambwa"]<-"Ng'ambwa_C" | |
# Merge | |
ShehiaShp<-merge(ShehiaShp,Shehia_Inc_Trav,by.x="ResShehia",by.y="Shehia",all.x=T) | |
ShehiaShp$Incidence_Travel<-(ShehiaShp$Shehia_Inc_Travel / ShehiaShp$Populati_1)*1000 | |
ShehiaShp$Incidence_Time_Kern<-(ShehiaShp$Shehia_Time_Kern / ShehiaShp$Populati_1)*1000 | |
ShehiaShp$Incidence_Raw<-(ShehiaShp$Shehia_Raw / ShehiaShp$Populati_1)*1000 | |
ShehiaShp$Incidence_Travel_Wet<-(ShehiaShp$Shehia_Inc_Travel_Wet / ShehiaShp$Populati_1)*1000 | |
ShehiaShp$Incidence_Time_Kern_Wet<-(ShehiaShp$Shehia_Time_Kern_Wet / ShehiaShp$Populati_1)*1000 | |
ShehiaShp$Incidence_Raw_Wet<-(ShehiaShp$Shehia_Raw_Wet / ShehiaShp$Populati_1)*1000 | |
ShehiaShp$Incidence_Travel_Dry<-(ShehiaShp$Shehia_Inc_Travel_Dry / ShehiaShp$Populati_1)*1000 | |
ShehiaShp$Incidence_Time_Kern_Dry<-(ShehiaShp$Shehia_Time_Kern_Dry / ShehiaShp$Populati_1)*1000 | |
ShehiaShp$Incidence_Raw_Dry<-(ShehiaShp$Shehia_Raw_Dry / ShehiaShp$Populati_1)*1000 | |
# Generate colors according to incidence | |
Cuts<-quantile(ShehiaShp$Incidence_Travel,prob=seq(0,1,0.1),na.rm=T) | |
Cuts_Wet<-quantile(ShehiaShp$Incidence_Travel_Wet,prob=seq(0,1,0.1),na.rm=T) | |
Cuts_Dry<-quantile(ShehiaShp$Incidence_Travel_Dry,prob=seq(0,1,0.1),na.rm=T) | |
Incidence_Travel_Col<-as.numeric(cut(ShehiaShp$Incidence_Travel, Cuts)) | |
Incidence_TimeKern_Col<-as.numeric(cut(ShehiaShp$Incidence_Time_Kern, Cuts)) | |
Incidence_Raw_Col<-as.numeric(cut(ShehiaShp$Incidence_Raw,Cuts)) | |
Incidence_Travel_Col_Wet<-as.numeric(cut(ShehiaShp$Incidence_Travel_Wet, Cuts_Wet)) | |
Incidence_TimeKern_Col_Wet<-as.numeric(cut(ShehiaShp$Incidence_Time_Kern_Wet, Cuts_Wet)) | |
Incidence_Raw_Col_Wet<-as.numeric(cut(ShehiaShp$Incidence_Raw_Wet,Cuts_Wet)) | |
Incidence_Travel_Col_Dry<-as.numeric(cut(ShehiaShp$Incidence_Travel_Dry, Cuts_Dry)) | |
Incidence_TimeKern_Col_Dry<-as.numeric(cut(ShehiaShp$Incidence_Time_Kern_Dry, Cuts_Dry)) | |
Incidence_Raw_Col_Dry<-as.numeric(cut(ShehiaShp$Incidence_Raw_Dry,Cuts_Dry)) | |
# Bind results | |
Colors<-rbind(Incidence_Travel_Col,Incidence_TimeKern_Col,Incidence_Raw_Col, | |
Incidence_Travel_Col_Wet,Incidence_TimeKern_Col_Wet,Incidence_Raw_Col_Wet, | |
Incidence_Travel_Col_Dry,Incidence_TimeKern_Col_Dry,Incidence_Raw_Col_Dry) | |
shinyServer(function(input, output) { | |
output$map <- renderPlot({ | |
# select wet or dry season | |
Season <- switch(input$season, | |
"Both" = 1, | |
"Wet" = 2, | |
"Dry" = 3) | |
Travel <- switch(input$travel, | |
"Travel history" = 1, | |
"Time kernal" = 2, | |
"No time" = 3) | |
Color <- Colors[Season*Travel,] | |
par(bg = "gray95") | |
plot(ShehiaShp,xlim=c(39,39.75),ylim=c(-6.5,-5.7), | |
col=cols[Color],border="gray60",lwd=1,asp=1) | |
},height=700,res=100) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment