Skip to content

Instantly share code, notes, and snippets.

View michaeldorman's full-sized avatar

Michael Dorman michaeldorman

View GitHub Profile
@michaeldorman
michaeldorman / plot_streets.R
Created May 14, 2020 18:46
Plot city streets
library(sf)
library(osmdata)
location = "Tel-Aviv, Israel"
# Get data
q = opq(bbox = location)
dat = add_osm_feature(q, key = "highway")
dat = osmdata_sf(dat)
lines = dat$osm_lines
library(sf)
library(ggplot2)
# Data
nc = st_read(system.file("shape/nc.shp", package="sf"))
map = nc
dat = nc[5, ]
# Plot 1
ggplot() +
@michaeldorman
michaeldorman / packages_proportion.R
Last active April 25, 2020 09:12
Calculate top 15 commonly used R packages given a directory with R scripts
# Directory with R scripts
setwd("~/Sync/BGU")
# Prepare data
files = list.files(pattern = "\\.R$", recursive = TRUE)
dat = lapply(files, readLines)
dat = lapply(dat, function(x) x[grepl("library\\(", x)])
dat = lapply(dat, function(x) gsub(".*library\\(", "", x))
dat = lapply(dat, function(x) gsub("\\).*", "", x))
dat = lapply(dat, function(x) gsub('"', '', x))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<html>
<head>
<title>Simple Leaflet Map</title>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css"
/>
</head>
loocv = function(formula, data) {
pred = rep(NA, nrow(data))
for(i in 1:nrow(data)) {
fit = lm(formula = formula, data = data[-i, ])
pred[i] = predict(fit, data[i, ])
}
@michaeldorman
michaeldorman / IMS_Map.R
Last active August 29, 2015 14:14
R script to create and publish interpolated temperature map of Israel
###############################################################
# Code to publish interpolated temperature map #
# based on current observations from the #
# Israel Meteorological Service (IMS) website #
# Author: Michael Dorman #
###############################################################
library(XML)
library(httr)
library(plyr)