Skip to content

Instantly share code, notes, and snippets.

View matt-dray's full-sized avatar
®️

Matt Dray matt-dray

®️
View GitHub Profile
@matt-dray
matt-dray / multi_plot_loop.R
Created January 15, 2017 14:02
Plot each y column against x and arrange in grids over multiple pages
library(ggplot2) # for plotting
library(gridExtra) # for arranging plots
# Create example dataframe
df <- data.frame(x = letters[1:10]
, y1 = sample(1:100, 10)
, y2 = sample(1:100, 10)
, y3 = sample(1:100, 10)
, y4 = sample(1:100, 10)
, y5 = sample(1:100, 10)
@matt-dray
matt-dray / loop_multi_file_assign_name.R
Created September 5, 2017 14:16
Loop read multiple files and assign object name based on filename
library(tidyverse)
library(stringr)
# list files in directory (in the format "x_y_z.csv")
list_files <- list.files("file/path")
for (i in seq_along(1:length(list_files))) {
# read the data
@matt-dray
matt-dray / loop_specify_combinations.R
Last active September 5, 2017 14:17
Loop through plots of specified column pairs of a dataframe
# purpose: loop through plots of specified column pairs of a dataframe
# don't want to compare all possible permutations
# also avoids nested loop of x and y
library(tidyverse) # for tibble and ggplot
# generate example dataframe
test_data <- tibble::tibble(x1 = rnorm(100)
, x2 = rnorm(100)

Keybase proof

I hereby claim:

  • I am matt-dray on github.
  • I am mattdray (https://keybase.io/mattdray) on keybase.
  • I have a public key ASD-cOiAVRNCc2XIcTt3U-nwNwA32uzNhPZPmHDiBDH8pAo

To claim this, I am signing this object:

@matt-dray
matt-dray / bin-using-hist-breaks.R
Created May 9, 2018 09:24
Using the binwidths of a histogram object to bin values in the dataframe
# 1. Fake dataset
df <- data.frame(id = 1:1000, value = sample(10000:50000, 1000))
# 2. Histogram object for accessing binwidths
hist_df <- hist(
df$value, # column of data to be binned
(50000-10000)/500 # bins of width 500 from 10k to 50k
)
@matt-dray
matt-dray / dfe_colour_palette.R
Created May 17, 2018 13:19
Convert RGB to hex for dept colour palette
# Approved colour palette for DfE
# Convert to hex the RGB values provided by the dept
# Matt Dray
# May 2018
# the main need is for plotting stats in publications
# inspiration from https://github.com/ukgovdatascience/govstyle
# this may eventually be added to the dfeR package
# function for converting from RGB to hex
@matt-dray
matt-dray / Rcrawler-link-extract.R
Created May 22, 2018 10:55
Using the Rcrawler package to extract hyperlinks containing certain strings from a website
@matt-dray
matt-dray / swfc_2016_fte.csv
Last active June 17, 2018 19:35
School Workforce Census 2016: processed version of original CSV containing columns full-time equivalent data and the joining key of URN (establishment Unique Reference Number).
We can't make this file beautiful and searchable because it's too large.
urn,workforce_fte,class_teacher_fte,teacher_fte,ta_fte,aux_fte
100000,32.4,10.3,14.3,11.3,1
100005,29.9,2,4.3,13,4.8
100006,22,7,10,9,2
100007,26.6,11.8,13.8,10.8,0
134643,14,3,5,6,0
136807,11.7,2.8,4.8,4.3,1
139837,10.6,3.7,5.7,4.2,0
140686,1,0,0,0.6,0.4
100008,53.2,16.8,20.4,17.1,9.7
@matt-dray
matt-dray / swfc_2016_headcount.csv
Last active June 18, 2018 08:48
School Workforce Census 2016: processed version of original CSV containing columns for school details and headcount data.
We can't make this file beautiful and searchable because it's too large.
la_number,establishment_number,la_name,urn,school_name,school_type,school_phase,region,workforce_count,class_teacher_count,teacher_count,ta_count,aux_staff_count
201,3614,City of London,100000,Sir John Cass's Foundation Primary School,LA maintained schools,Primary,Inner London,46,15,20,16,1
202,1048,Camden,100005,Thomas Coram Centre,LA maintained schools,Nursery,Inner London,36,3,6,13,8
202,1100,Camden,100006,CCfL Key Stage 4 PRU,LA maintained schools,Not applicable,Inner London,22,7,10,9,2
202,1101,Camden,100007,Camden Primary Pupil Referral Unit,LA maintained schools,Not applicable,Inner London,28,13,15,11,0
202,1103,Camden,134643,CCfL Key Stage 3 PRU,LA maintained schools,Not applicable,Inner London,14,3,5,6,0
202,2000,Camden,136807,St Luke's Church of England Primary,Free Schools,Primary,Inner London,16,4,6,7,1
202,2001,Camden,139837,Abacus Belsize Primary School,Free Schools,Primary,Inner London,12,4,6,5,0
202,2002,Camden,140686,Kings Cross Academy,Academies,Primary,Inner London,2,0,0,1,1
202,2019,Camden
bpID certainty errorDescription errorSnippet errorTitle issueID position priority ref resultTitle signature standards tID viewPortLocation xpath url
1 100 All images need an `alt` attribute. If you do not supply an `alt` attribute, that'll mean that users who ca not see the image will not understand what the image conveys. Make sure that the `alt` attribute value is a useful, concise, and clear description of the image. <img src="/images/hugo-logo.png" width="22" height="22"> This image is missing an `alt` attribute. 9b8bacf51f4a8ca12088ea7f9127f620 column: 77 , line: 197 97 https://tenon.io/bestpractice.php?bpID=1&tID=9 Provide an alt attribute for each `&lt;img&gt;` element. 0b423978ffbad8c6f96648e1938f17eb Web Content Accessibility Guidelines (WCAG) 2.0, Level A: 1.1.1 Non-text Content 9 {"bottom-right":{"x":612.484375,"y":9819.96875},"height":22,"top-left":{"x":590.484375,"y":9797.96875},"width":22} /html/body/div[1]/footer[1]/ul[1]/li[2]/a[1]/img[1] https://www.rostrum.blo