Skip to content

Instantly share code, notes, and snippets.

@rmnppt
rmnppt / shapeToDf.R
Created September 9, 2016 08:31
Script that takes a .shp file as an input and outputs a dataframe with the polygon information.
# process shapefile data
library(rgdal) # requires sp, will use proj.4 if installed
library(gpclib)
library(maptools)
library(ggplot2)
library(plyr)
gpclibPermit()
shpToDf <- function(directory, layer) {
map <- readOGR(dsn=directory, layer=layer)
@rmnppt
rmnppt / UKCities.R
Created September 7, 2015 14:30
uk cities with transparency mapped to population size
library(ggplot2)
library(magrittr)
library(dplyr)
library(maps)
data("world.cities")
world.cities %>%
filter(country.etc == "UK") %>%
ggplot(aes(x = long, y = lat, alpha = pop)) +