Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Mapping with R
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SERG
Mapping with R
Commits
e22eccb2
Commit
e22eccb2
authored
3 years ago
by
Tom Rushby
Browse files
Options
Downloads
Patches
Plain Diff
initial commit, lsoa example
parent
22541df2
No related branches found
No related tags found
1 merge request
!3
Cartograms example
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lsoaExample.Rmd
+112
-0
112 additions, 0 deletions
lsoaExample.Rmd
lsoaExample.html
+4685
-0
4685 additions, 0 deletions
lsoaExample.html
with
4797 additions
and
0 deletions
lsoaExample.Rmd
0 → 100644
+
112
−
0
View file @
e22eccb2
---
title: "LSOA mapping (Solent)"
author: "Thomas W Rushby"
date: "24/06/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(sf) # classes and functions for vector data
library(ggplot2)
library(tidyverse)
```
## Geography
```{r loadGeog}
inf <- here::here("data", "boundaries", "lsoa_solent.shp") # use here to specify the data location
message("Loading LSOA geometry from file")
sf_data <- sf::read_sf(inf)
head(sf_data)
```
```{r}
# Useful lookup spatial reference for CRS
# https://spatialreference.org/ref/epsg/27700/
st_coord_sys <- st_crs(sf_data) # check coord system
st_coord_sys # current coord system EPSG: 4326 (is what leaflet wants - good)
# transform the coord system if required
if(st_coord_sys$epsg != 4326){
sf_data <- st_transform(sf_data, "+proj=longlat +datum=WGS84")
}
# Create map (using leaflet) ----
# create popup first (using htmltools)
# by adding a column to sf_data object
library(htmltools)
sf_data$popup_text <-
paste("LSOA code: ","<b>", sf_data$LSOA11CD, "</b>",
'<br/>', 'LSOA: ', '<b>', sf_data$LSOA11NM, '</b>', ' ') %>%
lapply(htmltools::HTML)
# plot map
library(leaflet)
leaflet(sf_data %>% filter(LAD11NM == "Southampton")) %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addPolygons(color = "blue", fillColor = "blue", fillOpacity = 0.2, weight = 1.5, popup = ~(LSOA11NM), # popups clicked
label = ~(popup_text), # define labels
labelOptions = labelOptions( # label options
style = list("font-weight" = "normal", padding = "2px 2px"),
direction = "auto"),
highlight = highlightOptions(
weight = 5,
color = "#666",
fillOpacity = 0.7,
bringToFront = TRUE))
```
## Demand model
Start with current electricity demand ... we have stats for LSOAs from 2019:
```{r loadLSOAdata}
# electricity consumption data at MSOA level (pre downloaded)
inFile <- here::here("data", "energy", "LSOA_Dom_Elec", "LSOA_ELEC_2019.csv")
# fix inFile - use path to file ...
inFile <- "/Users/twr1m15/SotonGitLab/Personal/mapping-with-r/data/energy/LSOA_Dom_Elec/LSOA_ELEC_2019.csv"
lsoa_elecData <- readr::read_csv(inFile)
head(lsoa_elecData)
```
Join to geography data ...
```{r}
sf_data_elec <- left_join(sf_data,lsoa_elecData, by = c("LSOA11CD" = "Lower Layer Super Output Area (LSOA) Code"))
```
```{r}
# create popup first (using htmltools)
sf_data_elec$popup_text <-
paste("LSOA code: ","<b>", sf_data_elec$LSOA11CD, "</b>",
'<br/>', 'LSOA: ', '<b>', sf_data_elec$LSOA11NM, '</b>',
'<br/>', 'kWh/meter (median): ', '<b>', round(sf_data_elec$`Median domestic electricity consumption \n(kWh per meter)`,0), '</b>', 'kWh') %>%
lapply(htmltools::HTML)
# plot map
qpal <- colorQuantile("Reds", sf_data_elec$`Median domestic electricity consumption \n(kWh per meter)`, n = 9)
leaflet(sf_data_elec %>% filter(LAD11NM == "Southampton")) %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addPolygons(color = ~qpal(`Median domestic electricity consumption \n(kWh per meter)`), fillOpacity = 0.8, weight = 1.5, popup = ~(LSOA11NM), # popups clicked
label = ~(popup_text), # define labels
labelOptions = labelOptions( # label options
style = list("font-weight" = "normal", padding = "2px 2px"),
direction = "auto"),
highlight = highlightOptions(
weight = 5,
color = "#666",
fillOpacity = 0.7,
bringToFront = TRUE))
```
This diff is collapsed.
Click to expand it.
lsoaExample.html
0 → 100644
+
4685
−
0
View file @
e22eccb2
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment