This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # # # # # # # # # # # # # # # # # # # | |
# Simplify sp objects w. mapshaper # | |
# Needs https://nodejs.org installed # | |
# Tested on Windows and Linux # | |
# # # # # # # # # # # # # # # # # # # # | |
# # # # # # | |
# R setup # | |
# # # # # # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Households with a car and no professionals | |
synhhlds <- c(synhhlds, | |
sample( | |
filter(hhlds, | |
numprof == 0, | |
numcars > 0 | |
)$hhld, | |
popdist['Car','Other']) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- 1:99 | |
y = x^2 / exp(x) | |
plot(x, y) | |
pkgs <- c("downloader", "readxl") | |
install.packages(pkgs) | |
lapply(pkgs, library, character.only = T) | |
dir.create("big-data") | |
download("http://tinyurl.com/r-for-bd-8", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages("drat") | |
drat::addRepo("rcourses") | |
install.packages("nclRadvanced", type="source") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a class for bicycle data | |
wheelsize <- 559 # 26" wheel size, definited by 'bead seat diameter' (BSD) | |
size <- 21 * 25.4 # top tube length, inches converted to mm | |
top_tube_length <- 530 # top tobe length | |
x <- list(ws = wheelsize, s = size, ttl = top_tube_length) | |
class(x) <- "bike" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plotrix) | |
plot.bike <- function(x, ...){ | |
centre_back <- c(0, x$ws / 2) | |
centre_front <- c(x$ws + x$ttl + 100, x$ws / 2) | |
xlim <- c(-x$ws, centre_front[1] + x$ws / 2) | |
ylim <- c(0, x$ttl + x$ws/2 + 50) | |
plot.new() | |
plot.window(xlim, ylim) | |
draw.circle(x = centre_back[1], y = centre_back[2], radius = x$ws/2) | |
draw.circle(x = centre_front[1], y = centre_back[2], radius = x$ws/2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install devtools if needed | |
if(!require(devtools)) install.packages("devtools") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Loading MapInfo .mid files | |
library(rgdal) # rgdal library | |
drvs <- ogrDrivers() # ogr capabilities | |
drvs[grep("Inf", drvs$name),] # test MapInfo reading capability of gdal | |
f <- "folder/filename.mid" # filename | |
l <- ogrListLayers(f) # layer name | |
sp_object <- readOGR(f, layer = l[[1]]) # load! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download data | |
x <- c("ggmap", "geosphere", "sp") | |
lapply(x, library, character.only = TRUE) | |
download.file("https://dl.dropboxusercontent.com/u/15008199/tmp/origins.csv", "origins.csv", method = "wget") | |
origins <- read.csv("origins.csv") | |
os <- SpatialPoints(coords = origins, | |
proj4string = CRS("+init=epsg:4326")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download data | |
library(ggmap) # load the ggmap package | |
library(geosphere) | |
download.file("https://dl.dropboxusercontent.com/u/15008199/tmp/origins.csv", "origins.csv", method = "wget") | |
origins <- read.csv("origins.csv") | |
os <- SpatialPoints(coords = origins, | |
proj4string = CRS("+init=epsg:4326")) |