Skip to content

Instantly share code, notes, and snippets.

@erzk
erzk / shapefile_map_poland_1.R
Created April 1, 2016 22:08
plot ESRI shapefiles - vanilla
library(maptools)
# read the shapefile data
shpfile1 <- "POL_adm1.shp" # 2 - voivodeship-level
sh1 <- readShapePoly(shpfile1)
shpfile2 <- "POL_adm2.shp" # 2 - powiat-level
sh2 <- readShapePoly(shpfile2)
# create the overlapping plots
@erzk
erzk / shapefile_map_poland_2.R
Created April 1, 2016 22:22
plot ESRI shapefiles - Google Maps
# shapefile overlapping Google Maps
library(ggplot2)
library(ggmap)
library(rgdal)
# geographical centre of Poland
poland <- get_googlemap(c(lon=19.27, lat=52.03),
zoom = 6,
maptype = "satellite")
@erzk
erzk / shapefile_map_poland_3.R
Created April 1, 2016 22:24
plot ESRI shapefiles - Leaflet
# interactive leaflet plot
library(leaflet)
leaflet() %>%
addTiles() %>%
addPolygons(data = sh2,
weight = 2) %>%
addPolygons(data = sh1,
color = "red",
weight = 1)
@erzk
erzk / postcode_area
Created June 6, 2016 16:00
Postcode Area Regex - Tableau calculated field
// based on calculation from Tableau's website
REGEXP_EXTRACT([Postcode], "([A-Z][A-Z]?)")
# load this package to use HTTP verbs
library(httr)
postcode_lookup <- function(postcode) {
r <- GET(paste0("https://api.postcodes.io/postcodes/", postcode))
warn_for_status(r)
content(r)
}
# returns a list
@erzk
erzk / roh_performances_scraper.R
Last active November 6, 2016 14:03
Scrape the performance data from ROH collections
library(rvest)
# URL: http://www.rohcollections.org.uk/SearchResults.aspx?searchtype=performance&page=0&genre=Opera
performances <- c()
for (i in 0:233){
site_perf <- paste0("http://www.rohcollections.org.uk/SearchResults.aspx?searchtype=performance&page=",
i,
"&genre=Opera")
print(site_perf) # optional print to see the progress
@erzk
erzk / load_and_plot_nirs.R
Created December 18, 2016 23:30
This script shows how to load and plot fnirs data (.nirs format)
# install the package if not available with:
# install.packages("R.matlab")
library(R.matlab)
# load the nirs file
data <- readMat("Simple_Probe.nirs")
# get the available names
names(data)
dygraph(gbppln_xts,
main="British Pound (GBP) to Polish Zloty (PLN) 1996-2015",
ylab="GBP/PLN") %>%
dyRangeSelector(height = 50) %>%
dyEvent(date = "2004-05-01", "Poland joining the EU", labelLoc = "bottom") %>%
dyEvent(date = "2008-09-15", "Bankruptcy of Lehman Brothers", labelLoc = "top")
@erzk
erzk / serial_test.py
Created February 12, 2017 18:37
Testing a serial port with ETG-4000
import serial
port = serial.Serial('COM1', 9600, timeout=0)
port.write('A \r')
@erzk
erzk / fnirs_dygraph.R
Created June 2, 2017 22:09
interactive plot of fNIRS data
devtools::install_github("erzk/fnirsr")
library(dygraphs)
library(fnirsr)
file_path <- system.file("extdata", "Hitachi_ETG4000_24Ch_Total.csv", package = "fnirsr")
ETG_header <- load_ETG4000_header(file_path)
rawData <- load_ETG4000_data(file_path, ETG_header)
# prepare the events