diff --git a/README.md b/README.md index 8f14fe3..41e529d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Mapping Environmental Action -## A Welcome For the Uninitiated ## +## Why Reproducible Research? ## If you're new to github and reproducible research, welcome! It's nice to have you here. Github is ordinarily a place where software developers working on open source software projects deposit their code as they write software collaboratively. However, in recent years a number of scholarly researchers, especially people working on research which involves a digital component (including me!) have begun to deposit their papers in these same software repositories. The idea here is that you can download all of the source-code and data used in this paper alongside the actual text, run it yourself and ["reproduce" the results](http://kbroman.org/steps2rr/). This can serve as a useful safeguard, a layer of research transparency, and a cool teaching tool for other persons interested in doing similar work. @@ -22,7 +22,9 @@ This repository contains the code and writing towards a (working draft of a) sch I'd be extremely happy if someone found errors, or imagined a more efficient means of analysis and either reported them as an issue on this github repository or sent me an email. -The actual article is in `mapping_draft.Rmd`. +The actual article is in `mapping_draft.Rmd` and can be compiled using knitr (assuming you have R installed as well as required packages) using the script provided `knit_it_html.sh` + +Note: actual execution may take over an hour, as calls to `st_buffer` and `st_within` under `wilderness_data_prep` are computationally intensive. To compile more briskly, I recommend you comment out this final section and knit the markdown/html files. Paths in this folder are used mostly for R processing. Towards this end folders have the following significance: diff --git a/figures/.DS_Store b/figures/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/figures/.DS_Store differ diff --git a/figures/create_admin_barplot-1.pdf b/figures/create_admin_barplot-1.pdf new file mode 100644 index 0000000..974600b Binary files /dev/null and b/figures/create_admin_barplot-1.pdf differ diff --git a/figures/create_admin_barplot-1.png b/figures/create_admin_barplot-1.png new file mode 100644 index 0000000..c4fe680 Binary files /dev/null and b/figures/create_admin_barplot-1.png differ diff --git a/figures/create_choropleth_others-1.pdf b/figures/create_choropleth_others-1.pdf new file mode 100644 index 0000000..ae401e4 Binary files /dev/null and b/figures/create_choropleth_others-1.pdf differ diff --git a/figures/create_choropleth_others-1.png b/figures/create_choropleth_others-1.png new file mode 100644 index 0000000..a24d28f Binary files /dev/null and b/figures/create_choropleth_others-1.png differ diff --git a/figures/create_choropleth_others-2.pdf b/figures/create_choropleth_others-2.pdf new file mode 100644 index 0000000..ad35615 Binary files /dev/null and b/figures/create_choropleth_others-2.pdf differ diff --git a/figures/create_choropleth_others-2.png b/figures/create_choropleth_others-2.png new file mode 100644 index 0000000..a35346a Binary files /dev/null and b/figures/create_choropleth_others-2.png differ diff --git a/figures/create_choropleth_others-3.pdf b/figures/create_choropleth_others-3.pdf new file mode 100644 index 0000000..4ab7e27 Binary files /dev/null and b/figures/create_choropleth_others-3.pdf differ diff --git a/figures/create_choropleth_others-3.png b/figures/create_choropleth_others-3.png new file mode 100644 index 0000000..f05c48b Binary files /dev/null and b/figures/create_choropleth_others-3.png differ diff --git a/figures/create_simd_barplot-1.pdf b/figures/create_simd_barplot-1.pdf new file mode 100644 index 0000000..dc86b72 Binary files /dev/null and b/figures/create_simd_barplot-1.pdf differ diff --git a/figures/create_simd_barplot-1.png b/figures/create_simd_barplot-1.png new file mode 100644 index 0000000..194881b Binary files /dev/null and b/figures/create_simd_barplot-1.png differ diff --git a/figures/create_ur_barplot-1.pdf b/figures/create_ur_barplot-1.pdf new file mode 100644 index 0000000..e547239 Binary files /dev/null and b/figures/create_ur_barplot-1.pdf differ diff --git a/figures/create_ur_barplot-1.png b/figures/create_ur_barplot-1.png new file mode 100644 index 0000000..a78321b Binary files /dev/null and b/figures/create_ur_barplot-1.png differ diff --git a/figures/create_urbanrural_ecs_chart_choropleth-1.pdf b/figures/create_urbanrural_ecs_chart_choropleth-1.pdf new file mode 100644 index 0000000..2970817 Binary files /dev/null and b/figures/create_urbanrural_ecs_chart_choropleth-1.pdf differ diff --git a/figures/create_urbanrural_ecs_chart_choropleth-1.png b/figures/create_urbanrural_ecs_chart_choropleth-1.png new file mode 100644 index 0000000..d2d57f3 Binary files /dev/null and b/figures/create_urbanrural_ecs_chart_choropleth-1.png differ diff --git a/figures/plot_admin_ecs_admin2_choropleth-1.png b/figures/plot_admin_ecs_admin2_choropleth-1.png new file mode 100644 index 0000000..5200f2f Binary files /dev/null and b/figures/plot_admin_ecs_admin2_choropleth-1.png differ diff --git a/figures/plot_admin_ecs_choropleth-1.pdf b/figures/plot_admin_ecs_choropleth-1.pdf new file mode 100644 index 0000000..d6fe2a5 Binary files /dev/null and b/figures/plot_admin_ecs_choropleth-1.pdf differ diff --git a/figures/plot_admin_ecs_choropleth-1.png b/figures/plot_admin_ecs_choropleth-1.png new file mode 100644 index 0000000..72774d8 Binary files /dev/null and b/figures/plot_admin_ecs_choropleth-1.png differ diff --git a/figures/plot_admin_ecs_normed_choropleth-1.pdf b/figures/plot_admin_ecs_normed_choropleth-1.pdf new file mode 100644 index 0000000..5f5bc80 Binary files /dev/null and b/figures/plot_admin_ecs_normed_choropleth-1.pdf differ diff --git a/figures/plot_admin_ecs_normed_choropleth-1.png b/figures/plot_admin_ecs_normed_choropleth-1.png new file mode 100644 index 0000000..ca50df6 Binary files /dev/null and b/figures/plot_admin_ecs_normed_choropleth-1.png differ diff --git a/figures/plot_admin_ecs_normed_choropleth-2.pdf b/figures/plot_admin_ecs_normed_choropleth-2.pdf new file mode 100644 index 0000000..d50cead Binary files /dev/null and b/figures/plot_admin_ecs_normed_choropleth-2.pdf differ diff --git a/figures/plot_admin_ecs_normed_choropleth-2.png b/figures/plot_admin_ecs_normed_choropleth-2.png new file mode 100644 index 0000000..4249d63 Binary files /dev/null and b/figures/plot_admin_ecs_normed_choropleth-2.png differ diff --git a/figures/wilderness_plots-1.pdf b/figures/wilderness_plots-1.pdf new file mode 100644 index 0000000..d70727f Binary files /dev/null and b/figures/wilderness_plots-1.pdf differ diff --git a/figures/wilderness_plots-1.png b/figures/wilderness_plots-1.png new file mode 100644 index 0000000..b1f355b Binary files /dev/null and b/figures/wilderness_plots-1.png differ diff --git a/figures/wilderness_plots-2.pdf b/figures/wilderness_plots-2.pdf new file mode 100644 index 0000000..ed3367c Binary files /dev/null and b/figures/wilderness_plots-2.pdf differ diff --git a/figures/wilderness_plots-2.png b/figures/wilderness_plots-2.png new file mode 100644 index 0000000..082fcd1 Binary files /dev/null and b/figures/wilderness_plots-2.png differ diff --git a/mapping_draft.Rmd b/mapping_draft.Rmd index 5a53f18..c9da2c9 100644 --- a/mapping_draft.Rmd +++ b/mapping_draft.Rmd @@ -165,6 +165,7 @@ The programme launched officially in 2001 at Dunblane Cathedral in Stirling and In the case of Eco-Congregation Scotland, congregations are invited to begin by "registering" their interest in the programme by completing a basic one-sided form. The next step requires the completion of an award application, which includes a facilitated curriculum called a "church check-up" and after an application is submitted, the site is visited and assessed by third-party volunteer assessors. Sites are invited to complete additional applications for further awards which are incremental (as is the application process). Transition communities, at least in the period reflected on their map, go through a similar process (though this does not involve the use of a supplied curriculum) by which they are marked first as "interested," become "active" and then gain "official" status.[^1554162] # Representation by Regional Authorities (Council Areas) {.tabset} + ```{r import_admin_data, message=FALSE, warning=FALSE, include=FALSE} # read in polygon for Scottish admin boundaries # TODO: upload bundle of admin data to new zenodo repository and alter below to use new URLs @@ -363,8 +364,7 @@ ggplot() + legend.text = element_text(size = 9), legend.position = c(0.25, 0.85)) # TODO: shift to use of grobs: https://cran.r-project.org/web/packages/egg/vignettes/Ecosystem.html - -# ggsave("figure1.pdf") +# Adapt colour above to use oranges - scale_fill_brewer(palette = "Oranges") + ``` @@ -431,6 +431,9 @@ ggplot() + legend.text = element_text(size = 8), legend.position = c(0.25, 0.85)) # ggsave("figure2.pdf") +# Adapt colour above to use oranges - scale_fill_brewer(palette = "Oranges") + + + # Plot out second figure with normalised data: ggplot() + @@ -455,7 +458,10 @@ ggplot() + panel.border = element_rect(fill = NA, colour = "#cccccc"), legend.text = element_text(size = 8), legend.position = c(0.25, 0.85)) -# ggsave("figure3.pdf") + +# Adapt colour above to use oranges - scale_fill_brewer(palette = "Oranges") + +# TODO: Force bins to be consistently at count of 5? + ``` Given the way population and places of worship are unevenly distributed across Scotland it is important to represent data in terms of relative distribution. For this study, we attempted to "normalise" our data in two different ways, (1) as shown by Figure 2 above, by taking population figures from the 2011 census (see data sheet in Appendix A) and (2) by adjusting relative to the number of places of worship in each council region.[^15914204] The latter of these two can yield particularly unexpected results. Thus, of the `r length(pow_pointX)` "places of worship" in Scotland, the highest concentration is actually the `r as.character(admin_lev1$NAME_2[which.max(admin_lev1$pow_count)])` region, with `r max(admin_lev1$pow_count)`, second is `r max( admin_lev1$pow_count[admin_lev1$pow_count!=max(admin_lev1$pow_count)] )` (`r as.character(admin_lev1$NAME_2[which.max( admin_lev1$pow_count[admin_lev1$pow_count!=max(admin_lev1$pow_count)])] )`). Rank of Council Areas by population and number of places of worship is also included in Appendix A. @@ -500,9 +506,7 @@ ggplot(admin_gathered, scale_color_manual(labels = c("DTAS", "ECS", "Permaculture", "Transition")) ``` -## Concentration of groups {.tabset} - -### Choropleth +## Other environmental groups shown by concentration in administrative regions (NUTS) ```{r create_choropleth_others, fig.width=4, fig.show="hold", fig.cap="Figure 4"} @@ -531,6 +535,7 @@ ggplot() + legend.text = element_text(size = 8), legend.position = c(0.25, 0.85)) +# Adapt colour above to use oranges - scale_fill_brewer(palette = "Oranges") + ggplot() + geom_polygon(aes(x = long, y = lat, group = group, @@ -555,6 +560,9 @@ ggplot() + legend.text = element_text(size = 8), legend.position = c(0.25, 0.85)) +# Adapt colour above to use oranges - scale_fill_brewer(palette = "Oranges") + + + ggplot() + geom_polygon(aes(x = long, y = lat, group = group, fill = cut_interval(admin_lev1_fortified$dtas_count, 5)), @@ -577,13 +585,16 @@ ggplot() + panel.border = element_rect(fill = NA, colour = "#cccccc"), legend.text = element_text(size = 8), legend.position = c(0.25, 0.85)) + +# Adapt colour above to use oranges - scale_fill_brewer(palette = "Oranges") + + ``` -### Cartogram +## Cartogram Comparisons ```{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/ # # see here for example using sf: https://github.com/dreamRs/topogRam @@ -713,7 +724,8 @@ ggplot(urbanrural_gathered, ```{r create_urbanrural_ecs_chart_choropleth, fig.width=4, fig.cap="Figure 9"} -# Clipping work +# TODO: Clipping here to buildings shapefile +# TODO: Fix colour overlay for urbanrural to be in foreground and at 8 bins - add "fill= NA," outside aes? #title("difference(x,y)") #plot(x, border = 'grey') #plot(st_difference(st_union(y),st_union(x)), col = 'lightblue', add = TRUE) @@ -730,6 +742,7 @@ ecs_df <- as.data.frame(ecs) urbanrural_fortified <- join(urbanrural_fortified,urbanrural@data, by="id") # Make dots smaller - add outlines, & lines thinner +# Adapt colour above to use oranges - scale_fill_brewer(palette = "BrBG") + ggplot() + geom_polygon(aes(x = long, y = lat, group = group, fill = UR8FOLD), @@ -737,7 +750,7 @@ ggplot() + colour = 'black', alpha = .7, size = .005) + - geom_point(aes(X, Y, fill = NULL, group = NULL), size = 1, data=ecs_df, + geom_point(aes(X, Y, fill = NULL, group = NULL), size = 1, data = ecs_df, colour = "black", fill = "white", size = .15, @@ -758,6 +771,7 @@ ggplot() + panel.border = element_rect(fill = NA, colour = "#cccccc"), legend.text = element_text(size = 8), legend.position = c(0.25, 0.85)) + ``` @@ -880,6 +894,8 @@ ggplot(data=allgroups_gathered, ``` +## Discussing SIMD + Another crucial point of assessment relates to the relation of Eco-Congregation communities to the Scottish Index of Multiple Deprivation. This instrument aggregates a large variety of factors which can lead to deprivation including crime rates, employment levels, access to services (implicating remoteness), and literacy. By assessing ECS, Transition, and dtas against the deprivation scale, we can assess whether eco-congregations fall within particular demographics and also whether the fully aggregated SIMD measurement provides a useful point of comparison for our purposes. The SIMD essentially divides Scotland into 6407 geographic zones and then ranks them based on their relative deprivation. This data set can be split into any number of groups, but for our purposes we have settled on Quintiles, splitting the SIMD data set at every 1302 entries. We then measured where each transition group, ECS, and dtas fell within these zones and calculated how they fell into these five quintiles, from more to least deprived. The first, and most compelling finding is that, in general Eco-Congregation Scotland and Transition Scotland are both roughly the same and match the level of population distribution in the lowest quintile of the general SIMD measurement. 8% of transition groups and eco-congregation groups which have received awards and 9% of the population are located within this quintile. However, taken in relation to the distribution of places of worship in the lowest quintile, we find that eco-congregations are located at half the rate that places of worship are (15%) and dtass match this much more closely at 14%. Turning towards the top quintile, this pattern also holds, here both transition groups (21%) and eco-congregations (21% and 29% of awarded congregations) depart from the population distribution in this upper quintile (which is 10%). Again, general places of worship (at 11%) and DTASs (at 5%) take the opposite direction. We can say decisively that in communities which have been identified as good candidates for intervention to reduce deprivation, ECS and Transition are less likely, and they are over-represented at the areas which fall into the least deprived quintile. @@ -1002,6 +1018,31 @@ permaculture_wildland_row <- c(sum(apply(st_within(permaculture_sf, wildland, sp wildland_counts <- rbind(wildland_counts, permaculture_wildland_row) +# Generate dataframe based on forest_inventory buffers + +titles <- c("Within woodlands", "...50m", "...500m") + +ecs_forest_inventory_row <- c(sum(apply(st_within(ecs_sf, forest_inventory, sparse=FALSE), 1, any)), sum(apply(st_within(ecs_sf, st_buffer(forest_inventory, dist = 50), sparse=FALSE), 1, any)), sum(apply(st_within(ecs_sf, st_buffer(forest_inventory, dist = 500), sparse=FALSE), 1, any))) + +# TODO: add additional column with counts converted to percentages - use prop.table()? +ecs_forest_inventory_row <- rbind(titles, ecs_forest_inventory_row) + +pow_forest_inventory_row <- c(sum(apply(st_within(pow_pointX_sf, forest_inventory, sparse=FALSE), 1, any)), sum(apply(st_within(pow_pointX_sf, st_buffer(forest_inventory, dist = 50), sparse=FALSE), 1, any)), sum(apply(st_within(pow_pointX_sf, st_buffer(forest_inventory, dist = 500), sparse=FALSE), 1, any))) + +forest_inventory_counts <- rbind(ecs_forest_inventory_row, pow_forest_inventory_row) + +dtas_forest_inventory_row <- c(sum(apply(st_within(dtas_sf, forest_inventory, sparse=FALSE), 1, any)), sum(apply(st_within(dtas_sf, st_buffer(forest_inventory, dist = 50), sparse=FALSE), 1, any)), sum(apply(st_within(dtas_sf, st_buffer(forest_inventory, dist = 500), sparse=FALSE), 1, any))) + +forest_inventory_counts <- rbind(forest_inventory_counts, dtas_forest_inventory_row) + +transition_forest_inventory_row <- c(sum(apply(st_within(transition_sf, forest_inventory, sparse=FALSE), 1, any)), sum(apply(st_within(transition_sf, st_buffer(forest_inventory, dist = 50), sparse=FALSE), 1, any)), sum(apply(st_within(transition_sf, st_buffer(forest_inventory, dist = 500), sparse=FALSE), 1, any))) + +forest_inventory_counts <- rbind(forest_inventory_counts, transition_forest_inventory_row) + +permaculture_forest_inventory_row <- c(sum(apply(st_within(permaculture_sf, forest_inventory, sparse=FALSE), 1, any)), sum(apply(st_within(permaculture_sf, st_buffer(forest_inventory, dist = 50), sparse=FALSE), 1, any)), sum(apply(st_within(permaculture_sf, st_buffer(forest_inventory, dist = 500), sparse=FALSE), 1, any))) + +forest_inventory_counts <- rbind(forest_inventory_counts, permaculture_wildland_row) + ``` # Proximity to "Wilderness" @@ -1016,15 +1057,25 @@ So what did I discover? The results were inconclusive. First, it is important to # Output mmd tables using kable -knitr::kable(sssi_counts, caption = 'Group Counts within SSSIs') -knitr::kable(wildland_counts, caption = 'Group Counts within Wildland Areas') +sssi_counts %>% + kable(format = "html", col.names = colnames(sssi_counts), "Group counts within SSSIs") %>% + kable_styling(bootstrap_options = c("striped", "hover", "condensed", full_width = F, "responsive")) + +wildland_counts %>% + kable(format = "html", col.names = colnames(wildland_counts), caption = "Group counts within Wildland Areas") %>% + kable_styling(bootstrap_options = c("striped", "hover", "condensed", full_width = F, "responsive")) + +forest_inventory_counts %>% + kable(format = "html", col.names = colnames(forest_inventory_counts), caption = "Group counts within woodlands") %>% + kable_styling(bootstrap_options = c("striped", "hover", "condensed", full_width = F, "responsive")) ``` ```{r wilderness_plots} - +# TODO: Add ggplot overlaying all three wilderness area types with different colours for polygons + points of ecs with different colouration and colour intensity at 3 bins for dots within buffers at each level (0/50/500m) +# Note: there seems to be a problem with ggplot rendering these shapefiles - as it takes well over 10 hours to plot currently even on the smaller sssi shapefile. ``` @@ -1046,8 +1097,8 @@ admin_lev1_df <- as_data_frame(admin_lev1[,c(3,5,7,11,13)]) admin_lev1_df %>% kable(format = "html", col.names = colnames(admin_lev1_df)) %>% - kable_styling() %>% - kableExtra::scroll_box(width = "100%", height = "400px") + kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>% + kableExtra::scroll_box(width = "100%", height = "800px") ``` # Appendix B @@ -1058,8 +1109,8 @@ admin_lev1_prop_df <- as_data_frame(admin_lev1[,c(3:14,23:26)]) admin_lev1_prop_df %>% kable(format = "html", col.names = colnames(admin_lev1_prop_df)) %>% - kable_styling() %>% - kableExtra::scroll_box(width = "100%", height = "400px") + kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>% + kableExtra::scroll_box(width = "100%", height = "800px") ``` # Appendix C - Data by Urban / Rural Classification @@ -1069,7 +1120,14 @@ admin_lev1_prop_df %>% write.csv(urbanrural, "derivedData/urbanrural.csv", row.names=FALSE) # Output mmd tables using kable -knitr::kable(as_data_frame(urbanrural[,c(1,7:16)]), caption = 'Group Counts by Urban Rural Scale') + +urbanrural_table <- as_data_frame(urbanrural[,c(1,7:16)]) + +urbanrural_table %>% + kable(format = "html", col.names = colnames(urbanrural_table)) %>% + kable_styling(bootstrap_options = c("striped", "hover", "condensed")) %>% + kableExtra::scroll_box(width = "100%", height = "800px", caption = 'Group Counts by Urban Rural Scale') + ``` # Citations diff --git a/mapping_draft.html b/mapping_draft.html index f058fb0..dc748b6 100644 --- a/mapping_draft.html +++ b/mapping_draft.html @@ -11,7 +11,7 @@ - + Mapping Environmental Action in Scotland @@ -25,6 +25,7 @@ +