Skip to content

Instantly share code, notes, and snippets.

@erzk
erzk / Map_of_countries_in_top_100_CWUR.R
Created March 20, 2016 12:25
Kaggle dataset analysis - World University Rankings
# countries by the number of universities in the CWUR ranking
library(dplyr)
library(ggplot2)
library(RColorBrewer)
library(rworldmap)
cwur <- read.csv("cwurData.csv")
# data frames with the universities and count them by country
@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)
@erzk
erzk / loading_and_plotting_nirs_data.Rmd
Created December 18, 2016 23:44
RMarkdown file showing the nirs data analysis
---
title: "Loading and plotting nirs data"
author: "Eryk Walczak"
date: "18 December 2016"
output:
html_document: default
pdf_document: default
---
```{r setup, include=FALSE}
@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')