602
279
68
227
20
8
Last updated
27 May
Last Data Sync
27 May
Contribution
AGGP KRU
---
## https://rmarkdown.rstudio.com/flexdashboard/using.html#multiple_pages
#runtime: shiny
title: "Wavumbuzi Kenya"
author: "| AGEC"
output:
flexdashboard::flex_dashboard:
orientation: rows
logo: logo.min.jpg
source_code: embed
vertical_layout : fill ##Specify fill to vertically re-size charts so they completely fill the page and scroll to layout charts at their natural height, scrolling the page if necessary.
---
```{r}
#--------------------Required Packages----------------------------
# we'll be using the coronavirus() package.
#The input data for this dashboard is the dataset available from the {coronavirus} R package. Make sure to download the development version of the package to have the latest data:
#install.packages("devtools")
#devtools::install_github("RamiKrispin/coronavirus")
## To get the latest stats, use the function: update_datasets()
## which will prompt you to type in n/Y to download the Dev version. A restart of the R session may also be needed to access the updated dataset
suppressPackageStartupMessages({
library(shiny)
library(tidyverse)
library(flexdashboard)
library(plotly)
library(lubridate)
library(coronavirus)
library(knitr)
library(countrycode)
library(DT)
library(rgdal)
library(viridis)
library(readxl)
library(magrittr)
library(formattable)
library("highcharter")
#library(leaflet)
#library(geojsonio)
#library(sf)
})
options(highcharter.theme = hc_theme_google())
```
```{r}
clean.df <- read.csv("Wavumbuzi KE2021 Data Use for Decison Making.xlsx - clean2.csv")
clean.df=clean.df%>%
mutate(Status =ifelse(School.Active=="Active",'Active', "Inactive"))
```
Overview {data-icon="fa-tachometer"}
=======================================================================
Row {data-width=400}
-----------------------------------------------------------------------
### TOTAL
```{r}
confirmed_color <- "purple"
active_color <- "#1197fb"
recovered_color <- "forestgreen"
death_color <- "#ff6601"
samples=nrow(clean.df)
valueBox(
samples,
icon="far fa-user",
color="purple"
)
```
### CEMASTEA
```{r}
samples=nrow(clean.df%>%dplyr::filter(`Wavumbuzi.Partner.Affiliation`=="CEMASTEA"))
valueBox(
format(samples, big.mark = ","),
icon= "fas fa-chart-bar",
color= "#1197fb"
)
```
### Educate!
```{r}
samples=nrow(clean.df%>%dplyr::filter(`Wavumbuzi.Partner.Affiliation`=="Educate!"))
valueBox(
format(samples,big.mark = ","),
icon = "fas fa-chart-bar",
color="forestgreen"
)
```
### KPSA
```{r}
samples=nrow(clean.df%>%dplyr::filter(`Wavumbuzi.Partner.Affiliation`=="KPSA"))
valueBox(
format(samples,big.mark = ","),
color = "#ff6601",
icon = "fas fa-chart-bar"
)
```
### KAIS
```{r}
samples=nrow(clean.df%>%dplyr::filter(`Wavumbuzi.Partner.Affiliation`=="KAIS"))
valueBox(
format(samples,big.mark = ","),
color = "#ABA6BF",
icon = "fas fa-chart-bar"
)
```
### Own Volition
```{r}
samples=nrow(clean.df%>%dplyr::filter(`Wavumbuzi.Partner.Affiliation`=="Own Volition"))
valueBox(
format(samples,big.mark = ","),
color = "#5C6BC0",
icon = "fas fa-chart-bar"
)
```
```{r}
### **Number of cases per county in Kenya**
# reading in the Kenyan shapefiles
# If reading a shapefile, the data source name (dsn= argument) is the folder (directory) where the shapefile is, and the layer is the name of the shapefile (without the .shp extension)
getGisData = function(status){
kenya_shp=readOGR(dsn="data/kenyan-counties",layer="County",verbose = F)
# converting the shp file to a df
kenya_df=fortify(kenya_shp) # use broom::tidy(kenya_m) since fortify may be deprecated in the future
kenya_df$id=as.integer(kenya_df$id)
kenya_ctys=read_excel("data/counties.xlsx")
kenya_ctys %<>% select(-1)
kenya_ctys$County_ID = gsub("[[:punct:]]","",gsub("\\s*\\([^\\)]+\\)","",kenya_ctys$county))
kenya_ctys$County_ID=str_squish(kenya_ctys$County_ID)
kenya_ctys$County_ID=tolower(kenya_ctys$County_ID)
kenya_ctys$County_ID=gsub("[[:space:]]", "", kenya_ctys$County_ID)
sch_ctys=clean.df%>%
filter(Status%in%status)%>%
count(County)%>%select(County, Schools=n)
sch_ctys$County_ID = gsub("[[:punct:]]","",gsub("\\s*\\([^\\)]+\\)","",sch_ctys$County))
sch_ctys$County_ID=str_squish(sch_ctys$County_ID)
sch_ctys$County_ID=tolower(sch_ctys$County_ID)
sch_ctys$County_ID=gsub("[[:space:]]", "", sch_ctys$County_ID)
## Join
kenya_ctys=left_join(kenya_ctys,sch_ctys,by=c("County_ID"="County_ID"))
comp_df= left_join(kenya_df,kenya_ctys,by="id")
comp_df %<>% select(-c(order,hole,piece,id,group)) %>%
group_by(county) %>% arrange(desc(Schools)) %>%
ungroup()
# Rorder data + Add a new column with tooltip text
# with the data I had, I computed the mean coordinates per county to act as my centroid point
kenya_mean= comp_df %>% group_by(county,county_code,Schools) %>%
summarise(long=mean(long),lat=mean(lat)) %>%
mutate(tooltip=paste(
"County: ", county, "\n",
"Schools: ", Schools, sep = ""
)) %>%
filter(Schools>0) %>%
arrange(desc(Schools))
return(
list(
kenya_mean=kenya_mean,
comp_df=comp_df
)
)
}
```
Column
--------------------------------------------------------------------
###
```{r,fig.width=12, fig.height=8}
###
# ###
# { data-width=400 }
# Now we want to add another information. The number of cases per county will be mapped to the colour and the size of the bubbles. Note that the order of county matters! It is advised to show the most important information on top (center). This can been done sorting your dataset before making the plot.
kenya_mean=getGisData(c("Active", "Inactive"))$kenya_mean
comp_df=getGisData(c("Active", "Inactive"))$comp_df
kenya_map=ggplot() +
geom_polygon(data=comp_df,aes(x=long,y=lat,group=county_code,fill=county_code),linetype="dashed",color="white",lwd=0.09,show.legend = FALSE)+
geom_point(data=kenya_mean,aes(x=long,y=lat,color=Schools,size=Schools,text=tooltip),alpha=0.9)+
scale_size_continuous()+
scale_fill_viridis_c(option = "plasma", direction = -1)+
coord_equal()+
#ylim(-3,2)+
#xlim(20,40)
ggtitle("Number of Schools per county")+
theme(legend.position = "right",plot.title = element_text(hjust = 0.5))+
## to change the color of the fill aesthetic
scale_fill_gradient(low = "#bee0fa", high = "#97b2c7",space="Lab")+
labs(
x="longitude",
y="latitude"
)+theme_minimal()+theme(axis.title.x=element_blank())+theme(axis.title.y=element_blank())
ggplotly(kenya_map,tooltip = "tooltip")
```
###
```{r}
clean.df%>%count(County)%>%select(County, Schools=n)%>%arrange(Schools)%>%
hchart( "bar", hcaes(x = `County`, y = Schools),
options3d = list(enabled = TRUE, beta = 0, alpha = 0))%>%
hc_plotOptions(series = list(stacking = "normal",
dataLabels = list(enabled = TRUE)))%>%
hc_xAxis(title = list(text = ""), labels = list( step = 1)) %>%
hc_exporting(enabled = TRUE)
```
Active Schools {data-icon="fa-chart-pie"}
=======================================================================
Column
--------------------------------------------------------------------
###
```{r,fig.width=12, fig.height=8}
###
# ###
# { data-width=400 }
# Now we want to add another information. The number of cases per county will be mapped to the colour and the size of the bubbles. Note that the order of county matters! It is advised to show the most important information on top (center). This can been done sorting your dataset before making the plot.
kenya_mean=getGisData(c("Active"))$kenya_mean
comp_df=getGisData(c("Active"))$comp_df
kenya_map=ggplot() +
geom_polygon(data=comp_df,aes(x=long,y=lat,group=county_code,fill=county_code),linetype="dashed",color="white",lwd=0.09,show.legend = FALSE)+
geom_point(data=kenya_mean,aes(x=long,y=lat,color=Schools,size=Schools,text=tooltip),alpha=0.9)+
scale_size_continuous()+
scale_fill_viridis_c(option = "plasma", direction = -1)+
coord_equal()+
#ylim(-3,2)+
#xlim(20,40)
ggtitle("Number of Schools per county")+
theme(legend.position = "right",plot.title = element_text(hjust = 0.5))+
## to change the color of the fill aesthetic
scale_fill_gradient(low = "#bee0fa", high = "#97b2c7",space="Lab")+
labs(
x="longitude",
y="latitude"
)+theme_minimal()+theme(axis.title.x=element_blank())+theme(axis.title.y=element_blank())
ggplotly(kenya_map,tooltip = "tooltip")
```
###
```{r}
clean.df%>%
filter(Status%in%c("Active"))%>%
count(County)%>%select(County, Schools=n)%>%arrange(Schools)%>%
hchart( "bar", hcaes(x = `County`, y = Schools),
options3d = list(enabled = TRUE, beta = 0, alpha = 0))%>%
hc_plotOptions(series = list(stacking = "normal",
dataLabels = list(enabled = TRUE)))%>%
hc_xAxis(title = list(text = ""), labels = list( step = 1)) %>%
hc_exporting(enabled = TRUE)
```
County Analysis {data-icon="fa-chart-line"}
=======================================================================
Row {data-width=400}
-----------------------------------------------------------------------
### Active
```{r}
rate <- round(100*(nrow(clean.df%>%filter(School.Active=="Active"))/nrow(clean.df)))
gauge(rate, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(60, 100), warning = c(40, 59), danger = c(0, 39)
))
```
### Inactive
```{r}
rate <- round(100*(nrow(clean.df%>%filter(School.Active!="Active"))/nrow(clean.df)))
gauge(rate, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(60, 100), warning = c(40, 59), danger = c(0, 39)
))
```
Column
--------------------------------------------------------------------
###
```{r}
#as.datatable {formattable}-Generic function to create an htmlwidget
dtable=clean.df%>%count(County, `Wavumbuzi.Partner.Affiliation`)%>%select(County, Partner=Wavumbuzi.Partner.Affiliation,Schools=n)%>%arrange(County)
clean.df%>%count(County, `Wavumbuzi.Partner.Affiliation`)%>%select(County, Partner=Wavumbuzi.Partner.Affiliation,Schools=n)%>%arrange(County)%>%
hchart( "bar", hcaes(x = `County`, y = Schools, group = Partner),
options3d = list(enabled = TRUE, beta = 0, alpha = 0))%>%
hc_plotOptions(series = list(stacking = "normal",
dataLabels = list(enabled = TRUE)))%>%
hc_xAxis(title = list(text = ""),labels = list( step = 1)) %>%
hc_exporting(enabled = TRUE)
```
###
```{r}
#as.datatable {formattable}-Generic function to create an htmlwidget
dtable=clean.df%>%
mutate(Status =ifelse(School.Active=="Active",'Active', "Inactive"))%>%
count(County, `Status`)%>%select(County,Status,Schools=n)%>%arrange(County)
dtable%>%
hchart( "bar", hcaes(x = `County`, y = Schools, group = Status),
options3d = list(enabled = TRUE, beta = 0, alpha = 0))%>%
hc_plotOptions(series = list(stacking = "normal",
dataLabels = list(enabled = TRUE)))%>%
hc_xAxis(title = list(text = ""),labels = list( step = 1)) %>%
hc_exporting(enabled = TRUE)
```
Partner Analysis {data-icon="fa-chart-area"}
=======================================================================
Row {data-width=400}
-----------------------------------------------------------------------
### CEMASTEA | Active
```{r}
rate <- round(100*(nrow(clean.df%>%filter(School.Active=="Active" & `Wavumbuzi.Partner.Affiliation`=="CEMASTEA"))/nrow(clean.df%>%filter(`Wavumbuzi.Partner.Affiliation`=="CEMASTEA"))))
gauge(rate, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(60, 100), warning = c(40, 59), danger = c(0, 39)
))
```
### Educate! | Active
```{r}
rate <- round(100*(nrow(clean.df%>%filter(School.Active=="Active" & `Wavumbuzi.Partner.Affiliation`=="Educate!"))/nrow(clean.df%>%filter(`Wavumbuzi.Partner.Affiliation`=="Educate!"))))
gauge(rate, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(60, 100), warning = c(40, 59), danger = c(0, 39)
))
```
### KPSA | Active
```{r}
rate <- round(100*(nrow(clean.df%>%filter(School.Active=="Active" & `Wavumbuzi.Partner.Affiliation`=="KPSA"))/nrow(clean.df%>%filter(`Wavumbuzi.Partner.Affiliation`=="KPSA"))))
gauge(rate, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(60, 100), warning = c(40, 59), danger = c(0, 39)
))
```
### KAIS | Active
```{r}
rate <- round(100*(nrow(clean.df%>%filter(School.Active=="Active" & `Wavumbuzi.Partner.Affiliation`=="KAIS"))/nrow(clean.df%>%filter(`Wavumbuzi.Partner.Affiliation`=="KAIS"))))
gauge(rate, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(60, 100), warning = c(40, 59), danger = c(0, 39)
))
```
### Own Volition | Active
```{r}
rate <- round(100*(nrow(clean.df%>%filter(School.Active=="Active" & `Wavumbuzi.Partner.Affiliation`=="Own Volition"))/nrow(clean.df%>%filter(`Wavumbuzi.Partner.Affiliation`=="Own Volition"))))
gauge(rate, min = 0, max = 100, symbol = '%', gaugeSectors(
success = c(60, 100), warning = c(40, 59), danger = c(0, 39)
))
```
Column
--------------------------------------------------------------------
###
```{r}
#as.datatable {formattable}-Generic function to create an htmlwidget
clean.df%>%count( `Wavumbuzi.Partner.Affiliation`,County)%>%select(County, Partner=Wavumbuzi.Partner.Affiliation,Schools=n)%>%arrange(County)%>%
hchart( "column", hcaes(x = `Partner`, y = Schools, group =County ),
options3d = list(enabled = TRUE, beta = 0, alpha = 0))%>%
hc_plotOptions(series = list(stacking = "normal",
dataLabels = list(enabled = TRUE)))%>%
hc_xAxis(title = list(text = ""),labels = list( step = 1)) %>%
hc_exporting(enabled = TRUE)
```
###
```{r}
#as.datatable {formattable}-Generic function to create an htmlwidget
dtable=clean.df%>%
mutate(Partner=Wavumbuzi.Partner.Affiliation)%>%
mutate(Status =ifelse(School.Active=="Active",'Active', "Inactive"))%>%
count(Partner, `Status`)%>%select(Partner,Status,Schools=n)%>%arrange(Partner)
dtable%>%
hchart( "column", hcaes(x = `Partner`, y = Schools, group = Status),
options3d = list(enabled = TRUE, beta = 0, alpha = 0))%>%
hc_plotOptions(series = list(stacking = "normal",
dataLabels = list(enabled = TRUE)))%>%
hc_xAxis(title = list(text = ""),labels = list( step = 1)) %>%
hc_exporting(enabled = TRUE)
```
Aggregates {data-icon="fa-list"}
=======================================================================
###
```{r}
dtable=clean.df%>%count(County, `Wavumbuzi.Partner.Affiliation`)%>%select(County, Partner=Wavumbuzi.Partner.Affiliation,Schools=n)%>%arrange(County)
as.datatable(formattable(dtable,list(
area(col=("Schools"))~ normalize_bar("#B3E5FC",0.2))), options = list(
pageLength=1000, scrollX='400px', searching = FALSE, bPaginate = F))
```
###
```{r}
dtable=clean.df%>%
mutate(Status =ifelse(School.Active=="Active",'Active', "Inactive"))%>%
count(County, `Status`)%>%select(County,Status,Schools=n)%>%arrange(County)
as.datatable(formattable(dtable,list(
area(col=("Schools"))~ normalize_bar("#B3E5FC",0.2))), options = list(
pageLength=1000, scrollX='400px', searching = FALSE, bPaginate = F))
```
About {data-icon="fa-info"}
=======================================================================
**Last updated**
`r format(max(coronavirus::coronavirus$date), '%d %B')`
**Last Data Sync**
`r format(max(coronavirus::coronavirus$date), '%d %B')`
**Contribution**
AGGP KRU