mirror of
https://github.com/kidwellj/mapping_environmental_action.git
synced 2024-11-01 07:52:21 +00:00
added tabbed display, cartogram notes
This commit is contained in:
parent
bd2c334836
commit
21147ac021
|
@ -31,7 +31,7 @@ output:
|
||||||
|
|
||||||
```{r setup, include=FALSE}
|
```{r setup, include=FALSE}
|
||||||
require(knitr)
|
require(knitr)
|
||||||
knitr::opts_chunk$set(fig.path='figures/', warning=FALSE, echo=FALSE, message=FALSE)
|
knitr::opts_chunk$set(fig.path='figures/', warning=FALSE, echo=FALSE, message=FALSE, dpi=300, fig.width=7)
|
||||||
# TODO: consider implementing knitcitations - https://github.com/cboettig/knitcitations
|
# TODO: consider implementing knitcitations - https://github.com/cboettig/knitcitations
|
||||||
# TODO: fix simultaneous output towards PDF, see here: https://stackoverflow.com/questions/23621012/display-and-save-the-plot-simultaneously-in-r-rstudio
|
# TODO: fix simultaneous output towards PDF, see here: https://stackoverflow.com/questions/23621012/display-and-save-the-plot-simultaneously-in-r-rstudio
|
||||||
```
|
```
|
||||||
|
@ -459,6 +459,9 @@ ggplot(admin_gathered,
|
||||||
scale_color_manual(labels = c("DTAS", "ECS", "Permaculture", "Transition"))
|
scale_color_manual(labels = c("DTAS", "ECS", "Permaculture", "Transition"))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Concentration of groups {.tabset}
|
||||||
|
|
||||||
|
### Choropleth
|
||||||
|
|
||||||
```{r create_choropleth_others, fig.width=4, fig.show="hold", fig.cap="Figure 4"}
|
```{r create_choropleth_others, fig.width=4, fig.show="hold", fig.cap="Figure 4"}
|
||||||
|
|
||||||
|
@ -533,9 +536,52 @@ ggplot() +
|
||||||
panel.border = element_rect(fill = NA, colour = "#cccccc"),
|
panel.border = element_rect(fill = NA, colour = "#cccccc"),
|
||||||
legend.text = element_text(size = 8),
|
legend.text = element_text(size = 8),
|
||||||
legend.position = c(0.25, 0.85))
|
legend.position = c(0.25, 0.85))
|
||||||
|
```
|
||||||
|
|
||||||
|
### Cartogram
|
||||||
|
|
||||||
|
```{r create_cartograms, fig.width=4, fig.show="hold", fig.cap="Figure 4"}
|
||||||
|
|
||||||
# todo: plot as animated chorogram:
|
# todo: plot as animated chorogram:
|
||||||
# https://www.r-graph-gallery.com/331-basic-cartogram/
|
# https://www.r-graph-gallery.com/331-basic-cartogram/
|
||||||
|
# see here for example using sf: https://github.com/dreamRs/topogRam
|
||||||
|
|
||||||
|
library(cartogram)
|
||||||
|
|
||||||
|
# construct a cartogram using the population in 2005
|
||||||
|
afr_cartogram <- cartogram(afr, "POP2005", itermax=5)
|
||||||
|
|
||||||
|
# It is a new geospatial object: we can use all the usual techniques on it! Let's start with a basic ggplot2 chloropleth map:
|
||||||
|
library(tidyverse)
|
||||||
|
library(broom)
|
||||||
|
spdf_fortified <- tidy(afr_cartogram)
|
||||||
|
spdf_fortified = spdf_fortified %>% left_join(. , afr_cartogram@data, by=c("id"="ISO3"))
|
||||||
|
ggplot() +
|
||||||
|
geom_polygon(data = spdf_fortified, aes(fill = POP2005, x = long, y = lat, group = group) , size=0, alpha=0.9) +
|
||||||
|
coord_map() +
|
||||||
|
theme_void()
|
||||||
|
|
||||||
|
# As seen before, we can do better with a bit of customization
|
||||||
|
library(viridis)
|
||||||
|
ggplot() +
|
||||||
|
geom_polygon(data = spdf_fortified, aes(fill = POP2005/1000000, x = long, y = lat, group = group) , size=0, alpha=0.9) +
|
||||||
|
theme_void() +
|
||||||
|
scale_fill_viridis(name="Population (M)", breaks=c(1,50,100, 140), guide = guide_legend( keyheight = unit(3, units = "mm"), keywidth=unit(12, units = "mm"), label.position = "bottom", title.position = 'top', nrow=1)) +
|
||||||
|
labs( title = "Africa 2005 Population" ) +
|
||||||
|
ylim(-35,35) +
|
||||||
|
theme(
|
||||||
|
text = element_text(color = "#22211d"),
|
||||||
|
plot.background = element_rect(fill = "#f5f5f4", color = NA),
|
||||||
|
panel.background = element_rect(fill = "#f5f5f4", color = NA),
|
||||||
|
legend.background = element_rect(fill = "#f5f5f4", color = NA),
|
||||||
|
plot.title = element_text(size= 22, hjust=0.5, color = "#4e4d47", margin = margin(b = -0.1, t = 0.4, l = 2, unit = "cm")),
|
||||||
|
legend.position = c(0.2, 0.26)
|
||||||
|
) +
|
||||||
|
coord_map()
|
||||||
|
|
||||||
|
# Add animated version:
|
||||||
|
|
||||||
|
https://github.com/thomasp85/gganimate
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -626,6 +672,12 @@ ggplot(urbanrural_gathered,
|
||||||
|
|
||||||
```{r create_urbanrural_ecs_chart_choropleth, fig.width=4, fig.cap="Figure 9"}
|
```{r create_urbanrural_ecs_chart_choropleth, fig.width=4, fig.cap="Figure 9"}
|
||||||
|
|
||||||
|
# Clipping work
|
||||||
|
#title("difference(x,y)")
|
||||||
|
#plot(x, border = 'grey')
|
||||||
|
#plot(st_difference(st_union(y),st_union(x)), col = 'lightblue', add = TRUE)
|
||||||
|
#https://r-spatial.github.io/sf/articles/sf3.html
|
||||||
|
|
||||||
# Prepare urbanrural for tidyr and reinsert dropped columns
|
# Prepare urbanrural for tidyr and reinsert dropped columns
|
||||||
|
|
||||||
names(admin_lev1)[names(admin_lev1) == "newcode"] <- "id"
|
names(admin_lev1)[names(admin_lev1) == "newcode"] <- "id"
|
||||||
|
@ -725,6 +777,18 @@ allgroups_simd <- bind_rows(allgroups_simd, permaculture_simd)
|
||||||
allgroups_gathered <- gather(allgroups_simd, key = "simd_category", value = "rank", Overal_SIMD16_Rank, Income_Domain_2016_Rank, Employment_Domain_2016_Rank, Health_Domain_2016_Rank, Education_Domain_2016_Rank, Geographic_Access_Domain_2016_Rank, Crime_Domain_2016_Rank, Housing_Domain_2016_Rank)
|
allgroups_gathered <- gather(allgroups_simd, key = "simd_category", value = "rank", Overal_SIMD16_Rank, Income_Domain_2016_Rank, Employment_Domain_2016_Rank, Health_Domain_2016_Rank, Education_Domain_2016_Rank, Geographic_Access_Domain_2016_Rank, Crime_Domain_2016_Rank, Housing_Domain_2016_Rank)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## SIMD representation across domains by group {.tabset}
|
||||||
|
|
||||||
|
### Jitterplot
|
||||||
|
|
||||||
|
```{r create_simd_jitterplot}
|
||||||
|
# simd jitterplot
|
||||||
|
# jitterplot option, from Teutonico 2015, p. 63
|
||||||
|
# https://ggplot2.tidyverse.org/reference/geom_jitter.html
|
||||||
|
```
|
||||||
|
|
||||||
|
### Barplot
|
||||||
|
|
||||||
```{r create_simd_barplot}
|
```{r create_simd_barplot}
|
||||||
# Run plots
|
# Run plots
|
||||||
|
|
||||||
|
@ -760,11 +824,8 @@ ggplot(data=allgroups_gathered,
|
||||||
# write.csv(simd_percents_only, "derivedData/simd_percents_only.csv", row.names=FALSE)
|
# write.csv(simd_percents_only, "derivedData/simd_percents_only.csv", row.names=FALSE)
|
||||||
```
|
```
|
||||||
|
|
||||||
```{r create_simd_jitterplot}
|
### Boxplot
|
||||||
# simd jitterplot
|
|
||||||
# jitterplot option, from Teutonico 2015, p. 63
|
|
||||||
# https://ggplot2.tidyverse.org/reference/geom_jitter.html
|
|
||||||
```
|
|
||||||
|
|
||||||
```{r create_simd_boxplot}
|
```{r create_simd_boxplot}
|
||||||
|
|
||||||
|
@ -838,6 +899,7 @@ So what did I discover? The results were inconclusive. First, it is important to
|
||||||
|
|
||||||
```{r wilderness_table}
|
```{r wilderness_table}
|
||||||
# Calculate number of groups within polygons
|
# Calculate number of groups within polygons
|
||||||
|
# TODO: add other groups, run on additional shapefiles
|
||||||
|
|
||||||
# Sample code for use below
|
# Sample code for use below
|
||||||
# sum(apply(st_within(pow_pointX_sf, st_buffer(sssi, dist = 50), sparse=FALSE), 1, any))
|
# sum(apply(st_within(pow_pointX_sf, st_buffer(sssi, dist = 50), sparse=FALSE), 1, any))
|
||||||
|
|
Loading…
Reference in a new issue