-
Notifications
You must be signed in to change notification settings - Fork 0
/
jordan_map.Rmd
186 lines (123 loc) · 4.99 KB
/
jordan_map.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
---
title: "Syria Refugees in Jordan"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
```{r cars}
library(plyr)
library(ggplot2)
library(maptools)
library(ggmap)
library(scales)
library(raster)
library(readr)
# grab some of the key shapefile we will need.
sy_border <- getData("GADM", country="SY", level=0)
sy_map <- getData("GADM", country="SY", level=1)
jo_border <- getData("GADM", country="JO", level=0)
jo_map <- getData("GADM", country="JO", level=1)
# take a look at the shapefiles we just pulled
plot(jo_map)
plot(sy_map)
```
Let's take a look at the Syria shapefile to see what the admin districts are named.
```{r}
sy_map@data$NAME_1
```
Make sure your file has the same names as the districts. Names of places might be somewhat different when dealing with different langauges. For example UNHCR doesn't always report data in the same names as what might be found in the shapefile.
```{r}
sy_jordan <- read_csv("C:/Users/john.mataya/Desktop/Datasets/Syria Data/UNHRC/Custom_Camp/Syria_ref_in_Jordan_Origins.csv")
jo_df <- read_csv("C:/Users/john.mataya/Desktop/Datasets/Syria Data/UNHRC/Custom_Camp/Jordan_custom_camp.csv",
col_types = cols(Lat = col_number(),
Lon = col_number()))
sy_jordan$Destination <- NULL
sy_jordan <- sy_jordan[, -c(3:6)] # delete columns 5 through
sy_jordan <- sy_jordan[-c(15), ]
sy_jordan
```
And we can join our Refugee count data to the admin areas so that we can visualise it.
You can use the code below to join data from a csv to a shapefile, based on a common spatial value, here it is administrative boundaries, but it could be anything.
```{r}
sy_map@data$id <- rownames(sy_map@data)
# rename the columns in my sy_jordan dataframe to do the join
colnames(sy_jordan) <- c("NAME_1", "Refugees")
# perform the join
sy_map@data <- join(sy_map@data, sy_jordan, by="NAME_1")
# this step was necessary because for some reason the join was creating a single NA for the number of refgueess in Al-Hasakah provence. Here's I'm manually putting in the number by selecting the df[row number, col number] = value
sy_map@data[1, 15] = 5129
syria_df <- fortify(sy_map)
syria_df <- join(syria_df, sy_map@data, by="id")
syria_df
```
Now that we have some data ready, let's plot this in ggplot
```{r}
ggplot() + geom_polygon(data = syria_df, aes(x = long, y = lat, group = group, fill = Refugees), color = "black", size = 0.25)
```
Let's clean this up just a little bit
```{r}
ggplot() + geom_polygon(data = syria_df, aes(x = long, y = lat, group = group, fill = Refugees), color = "black", size = 0.25) +
scale_fill_distiller(name="Refugees", direction = 1, palette = "Reds", breaks = pretty_breaks(n = 5)) +
labs(title="Origins of Syrian Refugees in Jordan")
```
Now let's look at the Jordan map
```{r}
p <- ggplot() + geom_polygon(data = jo_map, aes(long, lat, group=group), fill = 'whitesmoke') +
geom_path(data=jo_map, aes(long,lat, group=group), color="grey", size=0.1) +
geom_point(data = jo_df, aes(x = Lon, y = Lat, color = factor(Camp), size = Refugees))
p
```
```{r}
# let's add cities - pull the lat and lon from google maps
city <- c('Amman')
Lat <- c(31.8360368)
Lon <- c(35.6674449)
cities <- data.frame(city, Lat, Lon)
head(cities)
str(cities)
```
```{r}
theme_opts<-list(theme(panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_blank(),
plot.background = element_blank(),
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
plot.title = element_blank()))
```
clean this map up just a little bit
```{r}
p + geom_point(data = cities, aes(x = Lon, y = Lat), size = 2, alpha = 0.5) + geom_text(data=cities, hjust=0.5, vjust=-0.5, aes(x=Lon, y=Lat, label=city), colour="black", size=3, alpha = 0.6) + theme_opts
```
```{r}
library(readr)
Jo <- read_csv("C:/Users/john.mataya/Desktop/Datasets/Syria Data/UNHRC/Custom_Camp/Jordan.csv",
col_types = cols(Camp = col_number(),
Lat = col_number(), Lon = col_number()))
head(Jo)
Jo$Country <- NULL
Jo$Lat <- NULL
Jo$Lon <- NULL
```
```{r}
p2 <- ggplot(Jo, aes(x = reorder(Location, Refugees), y = Refugees)) +
geom_bar(stat = "identity") +
coord_flip() +
labs(title=" ", subtitle=" ")+
labs(x=" ",y=" ") +
theme(plot.title = element_text(hjust = -1, vjust=1.12)) +
theme(plot.subtitle = element_text(hjust = -.35))
```
```{r}
theme_opts<-list(theme(panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
panel.background = element_blank(),
plot.background = element_blank(),
p1 + theme_opts
```