---
title: "Mutendere - February 2017"
output:
flexdashboard::flex_dashboard:
theme: lumen
orientation: rows
source_code: embed
---
```{r global, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(ggthemes)
library(lubridate)
library(leaflet)
library(rgdal)
library(forcats)
library(scales)
library(DT)
library(plotly)
data <- read.csv('~/Projects/Lusaka/MutBuildings.csv', header = TRUE)
data2 <- data
data3 <- data
data$averTagsBuild <- round(data$averTagsBuild, 2)
data$month <- month(data$month, label = TRUE)
data2$month <- ymd(data2$month)
BuildMut <- readOGR("/Users/bjenkellefsen/Projects/Lusaka/MutBuildW.geojson",
"OGRGeoJSON", require_geomType="wkbPolygon")
MutData <- BuildMut@data
#remove row names
rownames(MutData) <- c()
#convert timestamp to date object
MutData$timestamp <- as.Date(MutData$timestamp)
```
Mutendere {data-navmenu="suburbs"}
=======================================================================
row
-----------------------------------------------------------------------
###Buildings {.value-box}
```{r, echo=FALSE}
buildMut <- data %>%
filter(suburbs == "Mutendere") %>%
filter(month == "Feb") %>%
select(buildings)
valueBox(comma(buildMut), icon = "ion-ios-home-outline", color = "#9ecae1")
```
###Users {.value-box}
```{r}
usersMut <- data %>%
filter(suburbs == "Mutendere") %>%
filter(month == "Feb") %>%
select(usersBuild)
valueBox(usersMut, icon = "ion-ios-people-outline", color = "#9ecae1")
```
###Average number of tags {.value-box}
```{r}
tagsMut <- data %>%
filter(suburbs == "Mutendere") %>%
filter(month == "Feb") %>%
select(averTagsBuild)
tagsMut$averTagsBuild <- round(tagsMut$averTagsBuild, 2)
valueBox(tagsMut, icon = "ion-ios-pricetags-outline", color = "#9ecae1")
```
row {data-height=400}
-----------------------------------------------------------------------
###Buildings mapped
```{r, echo=FALSE, message=FALSE}
MutBuild <- MutData %>%
group_by(timestamp) %>%
summarise(numB = length(building)) %>%
mutate(cumsum = cumsum(numB))
#With a geom_line plot, you need to add group = 1 if only one group of observations
#to avoid the warning message each is obs is one group
gg <- ggplot(MutBuild, aes(timestamp, cumsum, group = 1, text = comma(cumsum)))
gg <- gg + geom_line(position = "identity", color="#6baed6")
gg <- gg + scale_y_continuous(labels = comma)
gg <- gg + scale_x_date(expand = c(0,0))
#gg <- gg + scale_x_date(date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major.x= element_blank())
gg <- gg + theme(panel.grid.major.y=element_line(linetype = "dashed"))
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks=element_line(colour="#ececec"))
gg <- gg + theme(axis.text.x=element_text(size=12))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```
row {data-height=600}
-------------------------------------------------------------------
###Buildings by type
```{r}
buildType <- BuildMut@data %>%
group_by(building) %>%
summarise(numB = length(building)) %>%
arrange(desc(numB))
gg <- ggplot(buildType, aes(x=numB, y=reorder(building, numB), text = comma(numB)))
gg <- gg + geom_segment(aes(xend = 0, yend=building), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=9))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```
### Missing fields in percentage
```{r}
MissAddMut <- BuildMut@data %>%
select(name, building.levels)
MeanAddrMut <- MissAddMut %>%
summarise_all(funs(mean(is.na(.))*100)) %>%
gather(Field, meanNA) %>%
mutate(Field = fct_recode(Field, "Floors" = "building.levels"))
gg <- ggplot(MeanAddrMut, aes(x=reorder(Field, meanNA), y=meanNA, text = round(meanNA, 2)))
gg <- gg + geom_segment(aes(xend = Field, yend=0), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + coord_flip()
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```
###Number of tags
```{r}
MutTagsBuild <- data3 %>%
filter(suburbs=="Mutendere") %>%
select(suburbs, month, tagsBuild) %>%
mutate(month = fct_recode(month, "2016-08-30" = "2016-08-01")) %>%
mutate(month = ymd(month))
gg <- ggplot(MutTagsBuild, aes(x=tagsBuild, y=month, text = comma(tagsBuild)))
gg <- gg + geom_segment(aes(xend = 0, yend=month), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + scale_y_date(breaks = as.Date(seq(as.Date("2016-08-28"),
as.Date("2017-02-28"), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```
Data
========================================================
```{r}
datatable(data, extensions = "Buttons",
options = list(dom="lfrtBip", buttons="csv"))
```
February 2017 {data-navmenu="Maps"}
========================================================
```{r, out.width = "1024px"}
knitr::include_graphics("February2017.jpg")
```