-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
159 lines (118 loc) · 3.55 KB
/
README.Rmd
File metadata and controls
159 lines (118 loc) · 3.55 KB
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# WEED (Wrangler for Emergency Events Database)
<!-- badges: start -->
<!-- badges: end -->
The goal of weed is to make the analysis of EM-DAT and related datasets easier, with most of the pre-processing abstracted away by functions in this package!
## Pre Requisites
Installation of the following packages :
readxl,
dplyr,
magrittr,
tidytext,
stringr,
tibble,
geonames,
countrycode,
purrr,
tidyr,
forcats,
ggplot2,
sf,
rgeos.
You also need a geonames user account if you intend to use the geocoding functionality of this package. Info on how to get one for free is available [here](https://www.geonames.org/manual.html).
## Installation
You can install the development version from [GitHub](https://github.com/rammkripa/weed) with:
``` r
# install.packages("devtools")
devtools::install_github("rammkripa/weed")
```
# Example
This is a basic example which shows a common ``weed`` workflow:
```{r example, include=FALSE}
library(weed)
library(tidyverse)
```
# Loading the Data
```{r ex2}
em <- read_emdat("/Users/ramkripa/Desktop/Tk2.xlsx", file_data = TRUE)
```
# Locationizing the Data
```{r ex3}
locationized_data <- em$disaster_data %>%
tail() %>%
split_locations(column_name = "Location") %>%
head()
locationized_data %>%
select(`Dis No`, Location,location_word, Latitude, Longitude, uncertain_location_specificity)
```
There are two problems with the Dataset as it exists here.
1. Half of our observations, even in this toy dataset, don't have Lat/Long data
2. The Lat/Long here is blatantly wrong.
Lat > 90?
Long > 360?
How is this possible?
So, we must recode this Lat/Long data
# Solving Problem 1: Our locations have very little Lat/Long data
```{r ex4}
locationized_data %>%
percent_located_locations(lat_column = "Latitude",
lng_column = "Longitude")
```
# Solving Problem 2: Geocoding the Locationized Data
A reminder that you need a geonames username to access this feature of the ``weed`` package.
More info available [here](https://www.geonames.org/manual.html).
```{r preex5, include = FALSE}
dummy_name = "rammkripa"
```
```{r ex5}
geocoded_data <- locationized_data %>%
geocode(geonames_username = dummy_name)
geocoded_data %>%
select(`Dis No`, Location,location_word, lat, lng)
```
Side note: These Lat/Long data look much better than before, given that Kenya is close to the equator!
# How effective was our geocoding?
```{r ex6}
geocoded_data %>%
percent_located_locations()
```
```{r ex62}
geocoded_data %>%
percent_located_disasters()
```
# Check if the locations are in a Lat Long Box!!
```{r ex77}
geocoded_data <- geocoded_data %>%
located_in_box(top_left_lat = 0,
top_left_lng = 35,
bottom_right_lat = -6,
bottom_right_lng = 40)
geocoded_data %>%
select(`Dis No`, Location,location_word, lat, lng, in_box)
```
# Check if Locations are in Shapefile!
```{r preex87, include = FALSE}
s_file_name = "~/Desktop/Projects/emdat_proj/shape_data/SH_mask.shp"
```
```{r ex87}
geocoded_data %>%
located_in_shapefile(shapefile_name = s_file_name) %>%
select(`Dis No`, Location, location_word, lat, lng, in_box, in_shape)
```
# Want to re-nest the location data?
```{r ex9}
geocoded_data %>%
nest_locations() %>%
select(`Dis No`, location_data)
```