Skip to content

Instantly share code, notes, and snippets.

View georgestagg's full-sized avatar

George Stagg georgestagg

View GitHub Profile
@georgestagg
georgestagg / visualisation.gsql
Created April 28, 2026 14:33
ggsql visualisation for #TidyTuesday 2026 W17
SELECT DISTINCT
CAST(FLOOR(YEAR(t.begin_effective_date) / 5) * 5 AS INTEGER) AS period,
s.section,
t.hts8,
t.agreement,
t.ad_val_rate * 100 AS rate
FROM read_csv('2026-W17/tariff_agricultural.csv', nullstr='NA') t
JOIN read_csv('2026-W17/hts_sections.csv') s
ON LEFT(t.hts8, 2) = s.chapter
WHERE t.ad_val_rate > 0 AND t.ad_val_rate < 1
@georgestagg
georgestagg / visualisation.gsql
Last active April 21, 2026 11:05
ggsql visualisation for #TidyTuesday 2026 W16
WITH financing AS (
SELECT country_name, year, value
FROM read_csv('financing_schemes.csv', delim = ',', header = true, quote = '"', dateformat = '%Y')
WHERE indicator_code = 'hf3_che'
), class AS (
SELECT economy, "Income group" as income_group FROM 'nwb_class.csv'
), country_payments AS (
SELECT country_name, year, value, income_group from financing
JOIN class ON financing.country_name = class.economy
), class_avg AS (
@georgestagg
georgestagg / app.R
Last active February 4, 2026 22:18
Shinylive for R - Loading data in various formats
library(shiny)
library(bslib)
library(duckplyr)
data1 <- readRDS("data.rds")
data2 <- read.csv("data.csv")
data3 <- df_from_parquet("data.parquet")
ui <- page_fillable(
titlePanel("Example: loading data formats"),
@georgestagg
georgestagg / mandeldrop.R
Created July 26, 2022 19:03
Mandelbrot set, transformed into a teardrop shape, in R and Rcpp
Rcpp::sourceCpp("mandeldrop.cpp")
xlims=c(-0.65,0.65)
ylims=c(-0.6,2.2)
m <- mandeldrop(xlims[[1]], xlims[[2]], ylims[[1]], ylims[[2]], 1560, 2160, 512)
# Colour palette from https://stackoverflow.com/q/48069990
rainbow=c(rgb(0.47,0.11,0.53),rgb(0.27,0.18,0.73),rgb(0.25,0.39,0.81),rgb(0.30,0.57,0.75),rgb(0.39,0.67,0.60),rgb(0.51,0.73,0.44),rgb(0.67,0.74,0.32),rgb(0.81,0.71,0.26),rgb(0.89,0.60,0.22),rgb(0.89,0.39,0.18),rgb(0.86,0.13,0.13))
cols=c(colorRampPalette(rainbow)(100),rev(colorRampPalette(rainbow)(100)),"black")