swapping out ggplot for tmap

This commit is contained in:
Jeremy Kidwell 2019-02-15 21:01:32 +00:00
parent c24f041a97
commit d037b23058
28 changed files with 392 additions and 177 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 268 KiB

After

Width:  |  Height:  |  Size: 268 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 KiB

After

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 299 KiB

After

Width:  |  Height:  |  Size: 298 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 307 KiB

After

Width:  |  Height:  |  Size: 306 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 KiB

After

Width:  |  Height:  |  Size: 199 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 KiB

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 370 KiB

After

Width:  |  Height:  |  Size: 370 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 333 KiB

After

Width:  |  Height:  |  Size: 332 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 309 KiB

After

Width:  |  Height:  |  Size: 308 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 311 KiB

After

Width:  |  Height:  |  Size: 310 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 KiB

After

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 334 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 699 KiB

View file

@ -31,6 +31,8 @@ output:
fig_caption: true
citation_package: natbib
latex_engine: xelatex
always_allow_html: yes
---
```{r setup, include=FALSE}
@ -198,9 +200,8 @@ proj4string(transition_wgs) <- CRS(wgs84)
transition <- spTransform(transition_wgs, bng)
transition_sf <- st_as_sf(transition, coords = c("X", "Y"), crs=27700)
# read in all_churches data and turn it into a SpatialPointsDataFrame
# TODO: need to remove all data points which are outside BNG area to
# resolve error
# read in all_churches data (data set generated by Jeremy Kidwell to replace PointX data used from Ordnance Survey)
# TODO: need to remove all data points which are outside BNG area to resolve error
# also need to make symmetrical with ECS denominations, add Methodist
# churches, remove nazarene and salvation army
@ -217,7 +218,6 @@ coordinates(pow_pointX) <- c("feature_easting", "feature_northing")
proj4string(pow_pointX) <- proj4string(admin_lev1)
pow_pointX_sf <- st_as_sf(pow_pointX, coords = c("X", "Y"), crs=27700)
# read in Scottish Community Dev. trust data and turn it into a SpatialPointsDataFrame
dtas <- read.csv("data/community-dev-trusts-2.6.csv")
coordinates(dtas) <- c("X", "Y")
@ -229,7 +229,6 @@ permaculture <- read.csv("data/permaculture_scot-0.8.csv")
coordinates(permaculture) <- c("X", "Y")
proj4string(permaculture) <- proj4string(admin_lev1)
permaculture_sf <- st_as_sf(permaculture, coords = c("X", "Y"), crs=27700)
```
```{r process_admin_data}
@ -298,10 +297,8 @@ admin_lev1$ecs_count_pownorm <- admin_lev1$ecs_count * admin_lev1$pow_percent
# Preserve scale
admin_lev1$ecs_count_popnorm_scaled <- admin_lev1$ecs_count_popnorm*(sum(admin_lev1$ecs_count)/sum(admin_lev1$ecs_count_popnorm))
admin_lev1$ecs_count_pownorm_scaled <- admin_lev1$ecs_count_pownorm*(sum(admin_lev1$ecs_count)/sum(admin_lev1$ecs_count_pownorm))
# Load population statistics for normalising data by population on admin_lev2
admin_lev2_pop <- read.csv("./data/scotland_and_wales_const_scotland_2011pop.csv")
admin_lev2 <- merge(x=admin_lev2, y=admin_lev2_pop, by.x = "code", by.y = "CODE")
@ -326,14 +323,6 @@ Perhaps the first important question to ask of these groups is, where are they?
# Note: for more information on EU administrative levels, see here: https://ec.europa.eu/eurostat/web/nuts/national-structures-eu
# TODO: Need to clip choropleth polygons to buildings shapefile
# Prepare admin_lev1 for tidyr and reinsert dropped columns
names(admin_lev1)[names(admin_lev1) == "newcode"] <- "id"
admin_lev1@data$id <- as.integer(rownames(admin_lev1@data))
admin_lev1@data$id <- admin_lev1@data$id-1
admin_lev1_fortified <- tidy(admin_lev1)
admin_lev1_fortified <- join(admin_lev1_fortified,admin_lev1@data, by="id")
# Draw initial choropleth map of ECS concentration (using sp, rather than sf data)
# Note: some ideas taken from here: https://unconj.ca/blog/choropleth-maps-with-r-and-ggplot2.html
# See also here: https://timogrossenbacher.ch/2016/12/beautiful-thematic-maps-with-ggplot2-only/
@ -342,29 +331,23 @@ admin_lev1_fortified <- join(admin_lev1_fortified,admin_lev1@data, by="id")
# Reference here: https://ggplot2.tidyverse.org/reference/cut_interval.html
# Reference re: size and scale for plots: http://sape.inf.usi.ch/quick-reference/ggplot2/size
ggplot() +
geom_polygon(aes(x = long, y = lat, group = group,
fill = cut_interval(admin_lev1_fortified$ecs_count, 5)),
data = admin_lev1_fortified,
colour = 'black',
alpha = .7,
size = .005) +
scale_fill_brewer(palette = "Oranges") +
labs(x = NULL, y = NULL, fill = "Groups",
title = "Figure 1a",
subtitle="Concentration of ECS groups",
caption = paste("Jeremy H. Kidwell :: jeremykidwell.info",
"Data: UK Data Service (OGL) & Jeremy H. Kidwell",
"You may redistribute this graphic under the terms of the CC-by-SA 4.0 license.",
sep = "\n")) +
theme_void() +
theme(text = element_text(family = "Arial Narrow", size = 9),
plot.title = element_text(size = 12, face = "bold"),
plot.margin = unit(c(0, 0.25, 0.0, 0.25), "in"),
panel.border = element_rect(fill = NA, colour = "#cccccc"),
legend.text = element_text(size = 9),
legend.position = c(0.25, 0.85))
# TODO: consider a shift to use of grobs: https://cran.r-project.org/web/packages/egg/vignettes/Ecosystem.html
# Switching to tmap from ggplot
tm_shape(admin_lev1) +
tm_fill(col = "ecs_count", palette = "Oranges") +
# tm_shape(ecs_sf) +
# tm_dots("red", size = .05, alpha = .4) +
# tm_scale_bar(position = c("left", "bottom")) +
tm_style("gray", title = "Figure 1a") +
tm_credits("Data: UK Data Service (OGL)
& Jeremy H. Kidwell,
Graphic is CC-by-SA 4.0",
position = c("right", "bottom")) +
tm_layout(title = "Concentration of ECS groups",
frame = FALSE,
title.size = .7,
inner.margins = c(0.1, 0.1, 0.05, 0.05)
)
```
@ -372,35 +355,21 @@ ggplot() +
```{r plot_admin_ecs_admin2_choropleth, fig.width=4, fig.show="hold", fig.cap="Figure 3"}
# Prepare admin_lev2 for tidyr and reinsert dropped columns
names(admin_lev2)[names(admin_lev2) == "newcode"] <- "id"
admin_lev2@data$id <- as.integer(rownames(admin_lev2@data))
admin_lev2@data$id <- admin_lev2@data$id-1
admin_lev2_fortified <- tidy(admin_lev2)
admin_lev2_fortified <- join(admin_lev2_fortified,admin_lev2@data, by="id")
ggplot() +
geom_polygon(aes(x = long, y = lat, group = group,
fill = cut_interval(admin_lev2_fortified$ecs_count, 5)),
data = admin_lev2_fortified,
colour = 'black',
alpha = .7,
size = .005) +
scale_fill_brewer(palette = "Oranges") +
labs(x = NULL, y = NULL, fill = "Groups",
title = "Figure 1b",
subtitle="Concentration of ECS groups (LAU)",
caption = paste("Jeremy H. Kidwell :: jeremykidwell.info",
"Data: UK Data Service (OGL) & Jeremy H. Kidwell",
"You may redistribute this graphic under the terms of the CC-by-SA 4.0 license.",
sep = "\n")) +
theme_void() +
theme(text = element_text(family = "Arial Narrow", size = 9),
plot.title = element_text(size = 12, face = "bold"),
plot.margin = unit(c(0, 0.25, 0.0, 0.25), "in"),
panel.border = element_rect(fill = NA, colour = "#cccccc"),
legend.text = element_text(size = 9),
legend.position = c(0.25, 0.85))
tm_shape(admin_lev2) +
tm_fill(col = "ecs_count", palette = "Oranges") +
# tm_shape(ecs_sf) +
# tm_dots("red", size = .05, alpha = .4) +
# tm_scale_bar(position = c("left", "bottom")) +
tm_style("gray", title = "Figure 3") +
tm_credits("Data: UK Data Service (OGL)
& Jeremy H. Kidwell,
Graphic is CC-by-SA 4.0",
position = c("right", "bottom")) +
tm_layout(title = "Concentration of ECS groups",
frame = FALSE,
title.size = .7,
inner.margins = c(0.1, 0.1, 0.05, 0.05)
)
```
@ -408,52 +377,34 @@ ggplot() +
```{r plot_admin_ecs_normed_choropleth, fig.width=4, fig.show="hold", fig.cap="Figure 2"}
# Plot out first figure with normalised data:
ggplot() +
geom_polygon(aes(x = long, y = lat, group = group,
fill = cut_interval(admin_lev1_fortified$ecs_count_pownorm_scaled, 5)),
data = admin_lev1_fortified,
colour = 'black',
alpha = .7,
size = .005) +
scale_fill_brewer(palette = "Oranges") +
labs(x = NULL, y = NULL, fill = "Groups",
title = "Figure 2",
subtitle="Concentration of ECS groups, data normalised by places of worship",
caption = paste("Jeremy H. Kidwell :: jeremykidwell.info",
"Data: UK Data Service (OGL) & Jeremy H. Kidwell",
"You may redistribute this graphic under the terms of the CC-by-SA 4.0 license.",
sep = "\n")) +
theme_void() +
theme(text = element_text(family = "Arial Narrow", size = 8),
plot.title = element_text(size = 12, face = "bold"),
plot.margin = unit(c(0, 0.25, 0.0, 0.25), "in"),
panel.border = element_rect(fill = NA, colour = "#cccccc"),
legend.text = element_text(size = 8),
legend.position = c(0.25, 0.85))
tm_shape(admin_lev1) +
tm_fill(col = "ecs_count_pownorm_scaled", palette = "Oranges") +
tm_style("gray", title = "Figure 4") +
tm_credits("Data: UK Data Service (OGL)
& Jeremy H. Kidwell,
Graphic is CC-by-SA 4.0",
position = c("right", "bottom")) +
tm_layout(title = "Concentration of ECS groups, data normalised by places of worship",
frame = FALSE,
title.size = .7,
inner.margins = c(0.1, 0.1, 0.05, 0.05)
)
# Plot out second figure with normalised data:
ggplot() +
geom_polygon(aes(x = long, y = lat, group = group,
fill = cut_interval(admin_lev1_fortified$ecs_count_popnorm_scaled, 5)),
data = admin_lev1_fortified,
colour = 'black',
alpha = .7,
size = .005) +
scale_fill_brewer(palette = "Oranges") +
labs(x = NULL, y = NULL, fill = "Groups",
title = "Figure 3",
subtitle="Concentration of ECS groups, data normalised by population",
caption = paste("Jeremy H. Kidwell :: jeremykidwell.info",
"Data: UK Data Service (OGL) & Jeremy H. Kidwell",
"You may redistribute this graphic under the terms of the CC-by-SA 4.0 license.",
sep = "\n")) +
theme_void() +
theme(text = element_text(family = "Arial Narrow", size = 8),
plot.title = element_text(size = 12, face = "bold"),
plot.margin = unit(c(0, 0.25, 0.0, 0.25), "in"),
panel.border = element_rect(fill = NA, colour = "#cccccc"),
legend.text = element_text(size = 8),
legend.position = c(0.25, 0.85))
tm_shape(admin_lev1) +
tm_fill(col = "ecs_count_popnorm_scaled", palette = "Oranges") +
tm_style("gray", title = "Figure 5") +
tm_credits("Data: UK Data Service (OGL)
& Jeremy H. Kidwell,
Graphic is CC-by-SA 4.0",
position = c("right", "bottom")) +
tm_layout(title = "Concentration of ECS groups, data normalised by places of worship",
frame = FALSE,
title.size = .7,
inner.margins = c(0.1, 0.1, 0.05, 0.05)
)
# TODO: Force bins to be consistently at count of 5?

File diff suppressed because one or more lines are too long

View file

@ -1,13 +1,13 @@
---
title: "Mapping Environmental Action in Scotland"
abstract:
# thanks: "Replication files are available on the author's Github account (https://github.com/kidwellj/mapping_environmental_action). **Current version**: February 14, 2019
# thanks: "Replication files are available on the author's Github account (https://github.com/kidwellj/mapping_environmental_action). **Current version**: February 15, 2019
style: jeremy1
author: "[Jeremy H. Kidwell](http://jeremykidwell.info)"
affiliation: University of Birmingham
institute: University of Birmingham
e-mail: "[j.kidwell@bham.ac.uk](mailto:j.kidwell@bham.ac.uk)"
date: "2019-02-14"
date: "2019-02-15"
bibliography: biblio.bib
linkcolor: black
geometry: margin=1in
@ -61,7 +61,7 @@ For the sake of comparison, we also measured the geographical footprint of two o
# Technical Background
Analysis was conducted using QGIS 2.8 and R 3.5.1, and data-sets were generated in CSV format.[^15541313] To begin with, I assembled a data set consisting of x and y coordinates for each congregation in Scotland and collated this against a variety of other specific data. Coordinates were checked by matching UK postcodes of individual congregations against geo-referencing data in the Office for National Statistics postcode database. In certain instances a single "congregation" is actually a series of sites which have joined together under one administrative unit. In these cases, each site was treated as a separate data point if worship was held at that site at least once a month, but all joined sites shared a single unique identifier. As noted above, two other datasets were generated for the sake of comparative analysis.[^177171536] These included one similar Environmental Non-Governmental Organisation (ENGO) in Scotland (1) Transition Scotland (which includes Scotland Communities Climate Action Network);[^15541342] and another community-based NGO, Scottish Community Development Trusts.[^158261232] As this report will detail, these three overlap in certain instances both literally and in terms of their aims, but each also has a separate identity and footprint in Scotland. Finally, in order to normalise data, we utilised the PointX POI dataset which maintains a complete database of Places of Worship in Scotland.[^15541614]
Analysis was conducted using QGIS 2.8 and R 3.5.2, and data-sets were generated in CSV format.[^15541313] To begin with, I assembled a data set consisting of x and y coordinates for each congregation in Scotland and collated this against a variety of other specific data. Coordinates were checked by matching UK postcodes of individual congregations against geo-referencing data in the Office for National Statistics postcode database. In certain instances a single "congregation" is actually a series of sites which have joined together under one administrative unit. In these cases, each site was treated as a separate data point if worship was held at that site at least once a month, but all joined sites shared a single unique identifier. As noted above, two other datasets were generated for the sake of comparative analysis.[^177171536] These included one similar Environmental Non-Governmental Organisation (ENGO) in Scotland (1) Transition Scotland (which includes Scotland Communities Climate Action Network);[^15541342] and another community-based NGO, Scottish Community Development Trusts.[^158261232] As this report will detail, these three overlap in certain instances both literally and in terms of their aims, but each also has a separate identity and footprint in Scotland. Finally, in order to normalise data, we utilised the PointX POI dataset which maintains a complete database of Places of Worship in Scotland.[^15541614]
# Background and History of Eco-Congregation Scotland
@ -207,13 +207,13 @@ While Roman Catholic churches make up just over 10% of the church buildings in S
```
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/kidwellj/OneDrive - bham.ac.uk/writing/201708_mapping_environmental_action/data", layer: "SG_UrbanRural_2016"
## Source: "/Users/jeremy/gits/mapping_environmental_action/data", layer: "SG_UrbanRural_2016"
## with 8 features
## It has 6 fields
```
```
## Reading layer `SG_UrbanRural_2016' from data source `/Users/kidwellj/OneDrive - bham.ac.uk/writing/201708_mapping_environmental_action/data/SG_UrbanRural_2016.shp' using driver `ESRI Shapefile'
## Reading layer `SG_UrbanRural_2016' from data source `/Users/jeremy/gits/mapping_environmental_action/data/SG_UrbanRural_2016.shp' using driver `ESRI Shapefile'
## Simple feature collection with 8 features and 6 fields
## geometry type: MULTIPOLYGON
## dimension: XY
@ -248,7 +248,7 @@ Of all the groups surveyed in this study, Eco-Congregation Scotland is the most
```
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/kidwellj/OneDrive - bham.ac.uk/writing/201708_mapping_environmental_action/data", layer: "sc_dz_11"
## Source: "/Users/jeremy/gits/mapping_environmental_action/data", layer: "sc_dz_11"
## with 6976 features
## It has 9 fields
```
@ -278,7 +278,7 @@ We can find divergence between transition communities and eco-congregation when
```
## Reading layer `SSSI_SCOTLAND' from data source `/Users/kidwellj/OneDrive - bham.ac.uk/writing/201708_mapping_environmental_action/data/SSSI_SCOTLAND.shp' using driver `ESRI Shapefile'
## Reading layer `SSSI_SCOTLAND' from data source `/Users/jeremy/gits/mapping_environmental_action/data/SSSI_SCOTLAND.shp' using driver `ESRI Shapefile'
## Simple feature collection with 15872 features and 7 fields
## geometry type: POLYGON
## dimension: XY
@ -289,14 +289,14 @@ We can find divergence between transition communities and eco-congregation when
```
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/kidwellj/OneDrive - bham.ac.uk/writing/201708_mapping_environmental_action/data", layer: "SSSI_SCOTLAND"
## Source: "/Users/jeremy/gits/mapping_environmental_action/data", layer: "SSSI_SCOTLAND"
## with 15872 features
## It has 7 fields
## Integer64 fields read as strings: PA_CODE
```
```
## Reading layer `WILDLAND_SCOTLAND' from data source `/Users/kidwellj/OneDrive - bham.ac.uk/writing/201708_mapping_environmental_action/data/WILDLAND_SCOTLAND.shp' using driver `ESRI Shapefile'
## Reading layer `WILDLAND_SCOTLAND' from data source `/Users/jeremy/gits/mapping_environmental_action/data/WILDLAND_SCOTLAND.shp' using driver `ESRI Shapefile'
## Simple feature collection with 42 features and 3 fields
## geometry type: MULTIPOLYGON
## dimension: XY
@ -307,13 +307,13 @@ We can find divergence between transition communities and eco-congregation when
```
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/kidwellj/OneDrive - bham.ac.uk/writing/201708_mapping_environmental_action/data", layer: "WILDLAND_SCOTLAND"
## Source: "/Users/jeremy/gits/mapping_environmental_action/data", layer: "WILDLAND_SCOTLAND"
## with 42 features
## It has 3 fields
```
```
## Reading layer `National_Forest_Inventory_Woodland_Scotland_2017' from data source `/Users/kidwellj/OneDrive - bham.ac.uk/writing/201708_mapping_environmental_action/data/National_Forest_Inventory_Woodland_Scotland_2017.shp' using driver `ESRI Shapefile'
## Reading layer `National_Forest_Inventory_Woodland_Scotland_2017' from data source `/Users/jeremy/gits/mapping_environmental_action/data/National_Forest_Inventory_Woodland_Scotland_2017.shp' using driver `ESRI Shapefile'
## Simple feature collection with 199698 features and 7 fields
## geometry type: POLYGON
## dimension: XY
@ -324,7 +324,7 @@ We can find divergence between transition communities and eco-congregation when
```
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/kidwellj/OneDrive - bham.ac.uk/writing/201708_mapping_environmental_action/data", layer: "National_Forest_Inventory_Woodland_Scotland_2017"
## Source: "/Users/jeremy/gits/mapping_environmental_action/data", layer: "National_Forest_Inventory_Woodland_Scotland_2017"
## with 199698 features
## It has 7 fields
## Integer64 fields read as strings: OBJECTID