Skip to content

Commit

Permalink
Update interactive map.
Browse files Browse the repository at this point in the history
  • Loading branch information
darrennorris committed Jul 22, 2024
1 parent 62af595 commit f781d05
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ remotes::install_github("darrennorris/testmap")
## Example

This is a basic example which shows a summary of
where *Podocnemis unifilis* is Endangered.
where *Podocnemis unifilis* is Endangered in different countries.
Another example with code to make a map is here:
https://darrennorris.github.io/testmap/articles/testmap.html

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ remotes::install_github("darrennorris/testmap")
## Example

This is a basic example which shows a summary of where *Podocnemis
unifilis* is Endangered.
unifilis* is Endangered in different countries.
Another example with code to make a map is here:
<https://darrennorris.github.io/testmap/articles/testmap.html>

Expand Down Expand Up @@ -76,15 +76,15 @@ points_bau_ffr |>
#> # A tibble: 9 × 10
#> COUNTRY pop_start pop_end pop_change change_lcl_95 change_ucl_95 length_river
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
#> 1 Bolivia 222170 94300. -0.576 -0.584 -0.567 22217
#> 1 Bolivia 222170 94300. -0.576 -0.583 -0.568 22217
#> 2 Brazil 1905550 712133. -0.626 -0.629 -0.624 190555
#> 3 Colombia 385520 199290. -0.483 -0.489 -0.477 38552
#> 4 Ecuador 83020 18194. -0.781 -0.791 -0.771 8302
#> 4 Ecuador 83020 18194. -0.781 -0.791 -0.770 8302
#> 5 French … 32980 17147. -0.48 -0.502 -0.458 3298
#> 6 Guyana 73720 55397. -0.249 -0.263 -0.234 7372
#> 6 Guyana 73720 55397. -0.249 -0.264 -0.234 7372
#> 7 Peru 473630 149614. -0.684 -0.689 -0.679 47363
#> 8 Suriname 57560 42552. -0.261 -0.278 -0.243 5756
#> 9 Venezue… 300220 185219. -0.383 -0.391 -0.376 30022
#> 8 Suriname 57560 42552. -0.261 -0.279 -0.244 5756
#> 9 Venezue… 300220 185219. -0.383 -0.390 -0.376 30022
#> # ℹ 3 more variables: length_endangered <dbl>, proportion_endangered <dbl>,
#> # threat_status <chr>
```
Expand Down
48 changes: 26 additions & 22 deletions vignettes/Interactive-map.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ table_country_ffr <- points_bau_ffr |>
mutate(flag_ff = if_else(Free.flowing == "yes", 1, 0)) |>
group_by(COUNTRY) |>
mutate(flag_e = if_else(fem_diff_t42 <= -0.5, 1, 0)) |>
summarise(length_river = n(),
summarise(pop_change = round(((sum(fem_t42) - sum(fem_t0)) / sum(fem_t0)), 3),
length_river = n(),
length_end = sum((flag_e)),
length_ff = sum(flag_ff),
prop_ff = round((sum(flag_ff) / length_river), 2)) |>
Expand All @@ -238,7 +239,7 @@ table_country_ffr <- points_bau_ffr |>
length_not_ff = length_river - length_ff
) |>
select(COUNTRY, prop_end, length_river, length_end, length_not_end,
select(COUNTRY, pop_change, prop_end, length_river, length_end, length_not_end,
prop_ff, length_ff, length_not_ff)
# Sum rows of each column if numeric
Expand All @@ -247,19 +248,20 @@ sumrow_ffr <- as.data.frame(lapply(table_country_ffr, func))
# Give name to the first element of the new data frame created above
sumrow_ffr[1] <- "Total"
# remove unwanted value
sumrow_ffr[c(2, 6)] <- NA
sumrow_ffr[c(2, 3, 7)] <- NA
```


```{r make-table-country-ffr, echo=FALSE}
options(knitr.kable.NA = '')
bind_rows(table_country_ffr, sumrow_ffr) |>
select(COUNTRY, prop_end, length_river, length_end, length_not_end) |>
knitr::kable(col.names = c("Country", "Endangered (prop)","river length (km)",
select(COUNTRY, pop_change, prop_end, length_river, length_end, length_not_end) |>
knitr::kable(col.names = c("Country", "Population change",
"Endangered (prop)","river length (km)",
"length End.", "length not End.")
)|>
kableExtra::column_spec(3:5, width = "2.5cm")
kableExtra::column_spec(3:6, width = "2.5cm")
```

Expand Down Expand Up @@ -363,14 +365,14 @@ fig_left <- tab_sum |>
droplevels() |>
filter(BASIN_NAME %in% c("Amazon", "Coastal North")) |>
ggplot(aes(x = COUNTRY, y = pop_change)) +
geom_rect(data=NULL,aes(xmin=-Inf, xmax=Inf, ymin = -0.2, ymax = -0.3),
fill="#F6DABF", alpha=0.2) +
geom_rect(data=NULL,aes(xmin=-Inf, xmax=Inf, ymin = -0.3, ymax = -0.5),
fill="#DEB688", alpha=0.2) +
geom_rect(data=NULL,aes(xmin=-Inf, xmax=Inf, ymin = -0.5, ymax = -0.8),
fill="#C09355", alpha=0.2) +
geom_rect(data=NULL,aes(xmin=-Inf, xmax=Inf, ymin = -0.8, ymax = -1),
fill="#A3720E", alpha=0.2) +
annotate(xmin=-Inf, xmax=Inf, ymin = -0.2, ymax = -0.3,
fill="#F6DABF", geom = 'rect', alpha=0.4) +
annotate(xmin=-Inf, xmax=Inf, ymin = -0.3, ymax = -0.5,
fill="#DEB688", geom = 'rect', alpha=0.4) +
annotate(xmin=-Inf, xmax=Inf, ymin = -0.5, ymax = -0.8,
fill="#C09355", geom = 'rect', alpha=0.4) +
annotate(xmin=-Inf, xmax=Inf, ymin = -0.8, ymax = -1,
fill="#A3720E", geom = 'rect', alpha=0.4) +
geom_col(aes(fill = COUNTRY)) +
geom_errorbar(aes(ymax = change_ucl_95, ymin = change_lcl_95),
width = 0.2) +
Expand All @@ -386,14 +388,14 @@ fig_right <- tab_sum |>
droplevels() |>
filter(BASIN_NAME %in% c("Coastal South", "Orinoco")) |>
ggplot(aes(x = COUNTRY, y = pop_change)) +
geom_rect(data=NULL,aes(xmin=-Inf, xmax=Inf, ymin = -0.2, ymax = -0.3),
fill="#F6DABF", alpha=0.2) +
geom_rect(data=NULL,aes(xmin=-Inf, xmax=Inf, ymin = -0.3, ymax = -0.5),
fill="#DEB688", alpha=0.2) +
geom_rect(data=NULL,aes(xmin=-Inf, xmax=Inf, ymin = -0.5, ymax = -0.8),
fill="#C09355", alpha=0.2) +
geom_rect(data=NULL,aes(xmin=-Inf, xmax=Inf, ymin = -0.8, ymax = -1),
fill="#A3720E", alpha=0.2) +
annotate(xmin=-Inf, xmax=Inf, ymin = -0.2, ymax = -0.3,
fill="#F6DABF", geom = 'rect', alpha=0.4) +
annotate(xmin=-Inf, xmax=Inf, ymin = -0.3, ymax = -0.5,
fill="#DEB688", geom = 'rect', alpha=0.4) +
annotate(xmin=-Inf, xmax=Inf, ymin = -0.5, ymax = -0.8,
fill="#C09355", geom = 'rect', alpha=0.4) +
annotate(xmin=-Inf, xmax=Inf, ymin = -0.8, ymax = -1,
fill="#A3720E", geom = 'rect', alpha=0.4) +
geom_col(aes(fill = COUNTRY)) +
geom_errorbar(aes(ymax = change_ucl_95, ymin = change_lcl_95),
width = 0.2) +
Expand All @@ -414,6 +416,8 @@ Table showing data values used in graph.

```{r make-table-basin-country-ffr, echo=FALSE}
tab_sum |>
filter(length_river > 21) |>
droplevels() |>
select(BASIN_NAME, COUNTRY, pop_change, length_river) |>
arrange(BASIN_NAME, COUNTRY) |>
knitr::kable(col.names = c("Basin", "Country", "population change",
Expand Down

0 comments on commit f781d05

Please sign in to comment.