Skip to content

Instantly share code, notes, and snippets.

@thoughtfulbloke
thoughtfulbloke / fluSARI22to25.csv
Last active December 20, 2025 08:02
Auckland Influenza SARI rates extracted from NZ PHFS Respiratory Illness Dashboard
Weekn Yearn WeekEnding Rate100k
1 2022 2022-01-05 0
2 2022 2022-01-12 0
3 2022 2022-01-19 0
4 2022 2022-01-26 0
5 2022 2022-02-02 0
6 2022 2022-02-09 0
7 2022 2022-02-16 0
8 2022 2022-02-23 0
9 2022 2022-03-02 0
@thoughtfulbloke
thoughtfulbloke / night.R
Created November 12, 2025 08:30
Night at 2025-11-12 21:25 NZDT
library(dplyr)
library(geosphere)
library(suncalc)
library(lubridate)
library(mapdata)
source("~/theme.R")
#21:25 locally is UTC 2025-11-11 08:25:00 at this time of year
# -47.5, 166
# -34.5, 180
@thoughtfulbloke
thoughtfulbloke / ordinalAndDontKnow.R
Created November 4, 2025 02:03
using geom_col to regulate don't knows to below the main plot
library(foreign)
library(dplyr)
library(tidyr)
library(ggplot2)
library(viridis)
library(ggpattern)
source("../theme.R")
sav23 <- suppressWarnings(read.spss("2_NZES23Release_100227.sav",
to.data.frame = TRUE, add.undeclared.levels = "sort"))
@thoughtfulbloke
thoughtfulbloke / NZtrade.R
Created September 26, 2025 02:52
Processing NZ Trade data
library(readr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(lubridate)
library(RcppRoll)
source("~/theme.R")
datafiles <- list.files(pattern="csv$")
# remove the older provisional files that I have the directory
library(readr)
library(dplyr)
library(tidyr)
library(ggplot2)
library(ggthemes)
source("~/theme.R")
WVS <- read_csv("~/Downloads/WVS_Cross-National_Wave_7_csv_v6_0.csv")
shorter <- WVS |>
filter(B_COUNTRY_ALPHA %in% c("DEU", "RUS","IND", "USA", "KOR", "NZL")) |>
select(B_COUNTRY_ALPHA, Q7:Q17)
library(ggplot2)
library(maps)
library(dplyr)
# while the position data in the maps package
# is very basic, that makes it simple to transform
nz_map <- map_data("nz")
nz_anti <- nz_map %>%
mutate(
@thoughtfulbloke
thoughtfulbloke / Excel_arrangement
Created February 10, 2025 20:34
NZ covid data organised for excel graphing
"Week_Ending","Border_Cases","Community_Cases","Deaths"
2020-02-23,0,0,0
2020-03-01,1,0,0
2020-03-08,4,2,0
2020-03-15,3,0,0
2020-03-22,56,22,0
2020-03-29,273,180,1
2020-04-05,160,350,0
2020-04-12,52,232,4
2020-04-19,16,81,7
@thoughtfulbloke
thoughtfulbloke / gist:7aeb5174d6ccc6e09ae170d4de0f16e9
Created January 18, 2025 03:25
proof of concept of batch add info from EXIF as text on photos using magick and exiftoolr in R
library(magick)
library(exiftoolr)
# Hard-coded folder path
folder <- "~/Desktop/photos"
# Function to process images
process_images <- function(folder) {
# Create the "texted" subfolder if it doesn't exist
texted_folder <- file.path(folder, "texted")
library(shiny)
library(magick)
ui <- fluidPage(
titlePanel("Image Upload and Text Overlay"),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose an Image File",
accept = c('image/png', 'image/jpeg')),
library(dplyr)
asLines <- readLines("d12.txt")
height <- length(asLines)
width <- nchar(asLines[1])
chars <- strsplit(paste(asLines, collapse = ""), "")[[1]]
aCropMatrix <- matrix(chars, nrow = height, byrow = TRUE)
aFieldMatrix <- matrix(1:length(chars), nrow = height, byrow = TRUE)
priorFieldMatrix <- matrix(rep(1, length(chars)), nrow = height, byrow = TRUE)
while (!identical(priorFieldMatrix, aFieldMatrix)) {