Skip to content

Instantly share code, notes, and snippets.

@thoughtfulbloke
thoughtfulbloke / Convert_Wordle_Share_to_Image_with_alt_text.R
Last active January 17, 2022 08:04
converts wordle share to an image and autogenerates accompanying alt text
library(ggplot2)
library(ggthemes)
library(dplyr)
colour_choice <- colorblind_pal()(3)
pasted_text = "PasteYourGameShareHre"
pasted_title <- gsub("\n\n.*", "", pasted_text)
title_short <- substr(pasted_title, 1, nchar(pasted_title) - 4)
pasted_grid <- gsub(".*[^/ ]/[^\\\n]+", "", pasted_text)
@thoughtfulbloke
thoughtfulbloke / MiQnumbers.R
Last active January 11, 2022 00:29
graph of positive covid cases in MiQ
library(rvest)
library(dplyr)
library(lubridate)
library(readr)
library(ggplot2)
library(ggthemes)
library(ggridges)
source("davidise.R")
# saving reports from the website as html into a folder
# called news_item_html
@thoughtfulbloke
thoughtfulbloke / omicron.R
Created January 1, 2022 04:01
Code for showing no community spread of omicron at present
library(readr)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(lubridate)
source("davidise.R") # graph styling and saving at twitter size
# extract colorblind pallete in case I want to make strategic use of it
six_cols <- (colorblind_pal()(6))
# daily full demographic csvs folder
cases_folder <- list.files("daily_all_cases", pattern = "csv$", full.names = TRUE)
@thoughtfulbloke
thoughtfulbloke / locad.R
Created November 3, 2021 22:12
rolling locations of interest per adult case of covid
library(dplyr)
library(lubridate)
library(ggplot2)
library(ggthemes)
library(tidyr)
library(RcppRoll)
# To look at locations of interest, I am taking my own set of infectious vs isolated cases from the 1pm news conference, the csv of individual case details to get location (available as a csv linked from https://www.health.govt.nz/our-work/diseases-and-conditions/covid-19-novel-coronavirus/covid-19-data-and-statistics/covid-19-case-demographics ), and a collection of the location of interest updates kindly provided by @nzgizmoguy on Twitter at https://github.com/gizmoguy/locations-of-interest
@thoughtfulbloke
thoughtfulbloke / vaxday.R
Last active October 16, 2021 03:09
vaxathon progress code
library(dplyr)
library(tidyr)
library(ggplot2)
library(ggthemes)
library(scales)
library(lubridate)
library(rvest)
system_time= paste("Update: ", Sys.time())
txt_data <- "
dhb, pop12+,dosed2
@thoughtfulbloke
thoughtfulbloke / OECDmortRate.R
Created September 17, 2021 04:07
calculating weekly mortality rates from the OECD data source
# OECD weekly all cause deaths to mortality rates
# Keep in mind, some countries (Sweden) exclude 3% of deaths from the weekly
# dataset as the day of death is not known
library(OECD)
library(dplyr)
country1 = "NZL"
country2 = "USA"
@thoughtfulbloke
thoughtfulbloke / lockdownvsCases.R
Created September 14, 2021 05:07
R code for graph showing NZ lockdown vs. Cases
# MoH is the ministry of Health all cases demographics csv file
# https://www.health.govt.nz/our-work/diseases-and-conditions/covid-19-novel-coronavirus/covid-19-data-and-statistics/covid-19-case-demographics#case-details
library(readr)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(lubridate)
# you need to provide csv name
file_name <- "covid_cases_2021-09-14.csv"
@thoughtfulbloke
thoughtfulbloke / davidise_graph.R
Created September 5, 2021 05:55
takes an unthemed ggplot graph and saves it in my preferred theme style, timestamped, on the desktop
davidise_graph <- function(x, savepath="~/Desktop/output", show_graph = TRUE){
# x is an unthemed ggplot graph but all the scales & labs are applied
# since this function wants a ggplot graph, I am assuming ggplot is loaded)
# assume Open Sans installed as a font
library(showtext)
# sort out your own font path declarations
font_add(family = "OpenSans", regular = "~/Library/Fonts/OpenSans-Light.ttf",
bolditalic = "~/Library/Fonts/OpenSans-BoldItalic.ttf",
italic = "~/Library/Fonts/OpenSans-LightItalic.ttf",
# Data
# https://www.health.govt.nz/our-work/diseases-and-conditions/covid-19-novel-coronavirus/covid-19-data-and-statistics/covid-19-case-demographics#case-details
library(readr)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(lubridate)
library(patchwork)
# you need to provide csv name
@thoughtfulbloke
thoughtfulbloke / analysing_nzpol_themes.R
Created July 14, 2021 03:42
Applying topic analysis of nzpol and relating it to user accounts
library(rtweet)
library(dplyr)
library(lubridate)
library(ggplot2)
library(tidytext)
library(topicmodels)
search_term <- "#nzpol"
corpus <- search_tweets(search_term, n=18000)
nzpol_utm <- corpus %>% select(screen_name, text) %>%
unnest_tokens(word,text, token="tweets") %>%