Mapping the 2022 election results.
To equip students with the necessary skills to design and make maps that communicate
as well as the relevant knowledge to manipulate spatial data with code.
library('tidyverse')
library('tmap')
library('dplyr')
library('st')
library('sf')
#election
data<-read.csv('election2022.csv')
#read shapefile
counties<-st_read('County.shp')
#merge the two
election<-merge(counties,data,by.x='county_id',by.y='Code')
election$Winner<-ifelse(election$Odinga>election$Ruto,'Raila','Ruto')
mypal<-c('blue','yellow')
tmap_mode('view')
tm_shape(election)+tm_polygons("Winner",palette=mypal,title="Candidate")+
tm_layout(title="2022 General Election", title.position = c("right","top"))
Contact [kevinkiprotich250@gmail.com] to get more information on the project