Skip to content

Instantly share code, notes, and snippets.

View rcatlord's full-sized avatar

rcatlord

View GitHub Profile
@rcatlord
rcatlord / .block
Created December 30, 2017 12:32
Regions of Iceland
license: cc-by-4.0
height: 500
scrolling: no
border: yes
@rcatlord
rcatlord / .block
Last active December 31, 2017 20:31
Places in Iceland
license: cc-by-4.0
height: 500
scrolling: no
border: yes
@rcatlord
rcatlord / .block
Last active January 6, 2018 18:28
Dot Plot
license: cc-by-4.0
height: 500
scrolling: no
border: yes
@rcatlord
rcatlord / equal_intervals_choropleth_map.R
Created February 20, 2018 16:05
R code for Medium post
ggplot() + # initialise a ggplot object
geom_sf(data = sf_gm_census, # add a simple features (sf) object
aes(fill = cut_number(percent, 5)), # group percent into equal intervals and use for fill
alpha = 0.8, # add transparency to the fill
colour = 'white', # make polygon boundaries white
size = 0.3) + # adjust width of polygon boundaries
scale_fill_brewer(palette = "PuBu", # choose a http://colorbrewer2.org/ palette
name = "No qualifications (%)") + # add legend title
labs(x = NULL, y = NULL,
@rcatlord
rcatlord / natural_breaks_choropleth_map.R
Created February 20, 2018 16:08
R code for Medium post
ggplot() +
geom_sf(data = sf_gm_census,
aes(fill = percent_class),
alpha = 0.8,
colour = 'white',
size = 0.3) +
scale_fill_brewer(palette = "PuBu",
name = "No qualifications (%)") +
labs(x = NULL, y = NULL,
title = "Residents with no qualifications in Greater Manchester, 2011",
@rcatlord
rcatlord / unclassed_choropleth_map.R
Created February 20, 2018 16:09
R code for Medium post
ggplot(sf_gm_census, aes(fill = percent)) +
geom_sf(alpha = 0.8, colour = 'white', size = 0.3) +
scale_fill_viridis(discrete = F,
name = "No qualifications (%)",
direction = -1,
guide = guide_colourbar(
direction = "horizontal",
barheight = unit(2, units = "mm"),
barwidth = unit(50, units = "mm"),
draw.ulim = F,
@rcatlord
rcatlord / script.R
Created February 20, 2018 16:47
Let's Make a Map in R - Medium post (20 February 2018)
## Let’s make a map in R ##
# Setup ---------------------------
install.packages("sf", "tidyverse", "classInt", "viridis")
library(sf) ; library(tidyverse) ; library(classInt) ; library(viridis)
# Reading spatial data ---------------------------
sf_gb <- st_read("https://opendata.arcgis.com/datasets/07194e4507ae491488471c84b23a90f2_3.geojson", quiet = TRUE)
glimpse(sf_gb)
st_geometry(sf_gb)
@rcatlord
rcatlord / euclidean_vs_network_distance.R
Created September 17, 2018 11:27
R code for Medium article
## Euclidean versus network distance ##
# load libraries and ggplot2 theme
library(tidyverse) ; library(sf) ; library(openrouteservice) ; library(geojsonio) ; library(ggplot2) ; library(ggspatial) ; library(ggrepel)
source("https://github.com/traffordDataLab/assets/raw/master/theme/ggplot2/theme_lab.R")
# set openrouteservice API key
ors_api_key("")
# provide coordinates (Denmark/Sweden border on Øresund Bridge)
@rcatlord
rcatlord / .block
Last active January 1, 2019 11:11
Gapminder with Vega-Lite
license: cc-by-4.0
height: 400
scrolling: no
border: yes
@rcatlord
rcatlord / .block
Last active December 23, 2018 12:35
Gapminder regions in Vega-Lite
license: cc-by-4.0
height: 400
scrolling: no
border: yes