-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
119 lines (93 loc) · 3.3 KB
/
README.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
---
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%",
warning = FALSE,
message = FALSE
)
```
# hexbur
<!-- badges: start -->
<!-- badges: end -->
The goal of hexbur is to provides several layers of information for Burkina Faso, useful for agricultural systems analysis and more.
`hexbur`is a lighweight package that provide hexagonal grid of about 340 km^2. The original idea of this work belongs to [@BjnNowak](https://github.com/BjnNowak).Benjamin, Thanks for building [`frex`](https://github.com/BjnNowak/frex).
## Installation
You can install the development version of hexbur from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("oousmane/hexbur")
```
## Basic hex grids plot
The package is based on a hexagonal grid of Burkina Faso, to which data layers can be added. This grid may be loaded as follows,
using the `hex_map()` function
```{r example}
library(hexbur)
hex <- hex_map() # with no args.
hex
```
`hex_map()` returns an `sf` object(spatial).
A very quick viz of hex grids can be performed using `{sf}` and for sure the `{tidyverse}`,
```{r cars}
#| warning
library(sf)
library(tidyverse)
# Simple hex grid map
ggplot()+
geom_sf(data = hex)
```
This a beautiful plot of hex grids. R can handle spatial data and produce beautiful maps. We can add, the border of country and make things prettier. `admin0_map()`,`admin1_map()`, `admin2_map()`and `admin3_map()` function allow you to download administrative boundary of Burkina Faso. These boundaries is distributed par [Humanitarian Data Exchange (HDX)](https://data.humdata.org). Below a better map of Burkina hex grid.
```{r}
admin0 <- admin0_map()
ggplot()+
geom_sf(data = hex, color = "grey90",fill="grey95")+
geom_sf(data = admin0,fill = NA,lwd=.5)+
theme_void()
```
## Add static layer
`hexbur` provides access to static and dynamic layer data. For now, only soil texture is supported (static layer). We will add further data layers as soon as possible.
The soil information (texture) comes from FAO HWSDv2, but we mad frequential analysis to determine dominant soil for each hex grid for 6 depths noted D1 to D6. Here is how to download soil information.
```{r}
# Get soil usda texture data
hwsd <- get_static_layer(layer="soil")
hwsd_sf <- left_join(hex,hwsd)
hwsd_sf <- hwsd_sf %>%
mutate(
across(
.cols = starts_with("D"),
.fns = num_to_usda # convert num to usda abreviation
)
) %>%
relocate(geom, .after = everything())
str(hwsd_sf)
```
With this dataset, we can visualize the distribution of soil texture for the first depth D1 (0-20 cm). Here how:
```{r}
ggplot()+
geom_sf(data = hwsd_sf,aes(fill=D1),color="grey95")+
scale_fill_manual(
values = hwsd_cols(),# function to provide convenient colors for soil
na.value = "grey"
)+
geom_sf(data = admin0,fill = NA,lwd=.5)+
guides(
fill = guide_legend(
position = "bottom",
title = "Texture du sol, couche D1 (0-20 cm)",
)
)+
labs(
title = "Type de sol dominant au Burkina Faso",
subtitle = "HWSD V2 | Grille hexagonale"
)+
theme_void(
)+
theme(
legend.title.position = "top"
)
```