-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
190 lines (126 loc) · 5.12 KB
/
index.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---
title: "Understanding the Comprehensive Mobility Plan for Bengaluru 2020"
site: distill::distill_website
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
# Learn more about creating websites with Distill at:
# https://rstudio.github.io/distill/website.html
# Learn more about publishing to GitHub Pages at:
# https://rstudio.github.io/distill/publish_website.html#github-pages
library(sf)
library(tidyverse)
library(tmap)
library(wesanderson)
tmap_mode("view")
tmap_options(check.and.fix = TRUE)
```
```{css, echo=FALSE}
d-title {
display:none;
}
```
<!-- Use a HTML break to add a little white space between the title and the map -->
<br>
```{r}
# I want the home screen to contain an interactive map of Bangalore which shows all the projects proposed in the Comprehensive Mobility Plan for Bengaluru 2020. The map needs to have relevant boundaries (BBMP Ward, BMRDA) in addition to the projects. Also, projects will need to be categorized to make it easier to understand.
# Now load in the dataset for this map. To start with, its going to have just points.
bangaloreCMPProjects <- readxl::read_xlsx(here::here("data/raw-data/bangaloreCMP2020Projects.xlsx"))
# Okay. I tried working with all projects in one DF but its makes sense to split them by project type. Then I can make the pop-up info more useful.
# Filter out the locations that are not geo-located yet
geoRefProjects <- bangaloreCMPProjects %>%
filter(!is.na(location)) %>%
separate(location, sep = ", ", into = c("lon", "lat"))
# Convert lat and long into geometry
geoRefProjects <- geoRefProjects %>%
st_as_sf(coords = c("lat", "lon"), crs = 4326) %>%
st_transform(3857)
# Define a Palette
myPalette <- wes_palette("FantasticFox1")
```
```{r}
# BASE MAP
# The CMP 2020 defines the study area as the whole of Bengaluru Metropolitan Area (1294.00 Sq.Km), part of Bangalore-Mysore Infrastructure Corridor Area (79.14 Sq.Km) and a part of Bangalore International Airport Area Local Planning Authority (227.85 Sq.Km). BUT, I don't see a map which explicitly shows these areas. :/
# Till I figure that out, I'll show the BBMP and metropolitan area boundaries.
# First, I will set up a base map with the BBMP ward boundaries.
bangaloreWardBoundary <- read_sf(here::here("data/raw-data/bangaloreWardBoundary.shp"))
bangaloreWards <- readRDS(here::here("data/raw-data/bangaloreWardMap.rds"))
# Transform it for consistency
bangaloreWardBoundary <- bangaloreWardBoundary %>%
st_transform(3857)
bangaloreWards <- bangaloreWards %>%
st_transform(3857)
# I'll draw the base map here. I want a thicker border for the overall outline of the wards and thinner lines showing individual wards.
mapBase <- tm_shape(bangaloreWardBoundary) +
tm_borders(col = "#000000",
lwd = 2) +
tm_shape(bangaloreWards) +
tm_borders(col = "#000000",
lwd = 0.5)
```
```{r}
# Clean-up variables
geoRefProjects <- geoRefProjects %>%
rename(ID = "id",
Type = "type",
Description = "description_0",
`Budget(in Cr.)` = "budget")
# Re-order variables
geoRefProjects <- geoRefProjects %>%
select(Type, ID, Description, `Budget(in Cr.)`)
```
```{r, layout="l-screen-inset", fig.height= 6.75}
# Create map viz
mapBase +
geoRefProjects %>%
mutate(budgetDisplay = case_when(is.na(`Budget(in Cr.)`) ~ 1,
TRUE ~ `Budget(in Cr.)`)) %>%
tm_shape() +
tm_dots(col = "Type",
border.col = "Black",
size = "budgetDisplay",
alpha = 0.9,
palette = myPalette,
popup.vars = c("ID", "Type", "Description", "Budget(in Cr.)")) +
tm_view(view.legend.position = c("left", "bottom"))
```
```{r}
# STAT CALCULATION
# I'd like to display counts about the total number of projects in the CMP and the number of projects that have been geo-referenced. It'll help show that things are still in progress and is also an indicator of the complexity of things.
# Total projects should be a static amount as counted from the CMP
# Georeferenced project count
geoRefCount <- geoRefProjects %>%
count() %>%
st_set_geometry(NULL) %>%
select(n)
```
<center>
### `r geoRefCount` projects have been geo-referenced as of `r format(Sys.Date(), "%d %B, %Y")`
</center>
---
```{r}
# I want a table to display the non-georefed projects
nonGeoRefProjects <- bangaloreCMPProjects %>%
filter(is.na(location)) %>%
select(-location)
nonGeoRefProjects <- nonGeoRefProjects %>%
rename(ID = "id",
Type = "type",
Description0 = "description_0",
Description1 = "description_1",
Description2 = "description_2",
`Budget(in Cr.)` = "budget") %>%
select(ID, Type, Description0, `Budget(in Cr.)`)
# I also want to show the count of non-georefed projects
nonGeoRefCount <- nonGeoRefProjects %>%
count() %>%
select(n)
```
<center>
### `r nonGeoRefCount` projects are queued for geo-referencing as of `r format(Sys.Date(), "%d %B, %Y")`
</center>
```{r, layout="l-screen-inset", fig.height= 6.75}
rmarkdown::paged_table(nonGeoRefProjects,
options = list(rows.print = 20,
cols.print = 7))
```