Skip to content

Instantly share code, notes, and snippets.

@johnmackintosh
johnmackintosh / Coin flips.R
Created October 30, 2016 08:53
Probability of n consecutive heads in a row from successive coin flips
library(ggplot2)
library(ggrepel)
library(scales)
library(ggExtra)
library(ggthemes)
n<- c(1:10)
flips<- 2*(2^n-1) #number of coin flips required
prob <- 0.5^n # probability of achieving n in a row
percentage<-(round(prob,4)*100)
@johnmackintosh
johnmackintosh / jekyll blog links.txt
Last active November 26, 2016 22:54
Help for jekyll blogging
@johnmackintosh
johnmackintosh / Calendarplot.R
Last active October 30, 2018 05:00
calendar plots in R
library(ggplot2)
library(lubridate)
library(tidyr)
library(viridis)
#library(extrafont) # optional
library(lubridate)
library(gridExtra)
library(ggExtra)
library(dplyr)
@johnmackintosh
johnmackintosh / HeatmapHrByDay.R
Last active February 21, 2024 10:19
How I made the hourly~daily~monthly~yearly heatmap : https://www.r-graph-gallery.com/283-the-hourly-heatmap.html
# https://www.r-graph-gallery.com/283-the-hourly-heatmap.html
library(ggplot2)
library(dplyr) # easier data wrangling
library(viridis) # colour blind friendly palette, works in B&W also
library(Interpol.T) # will generate a large dataset on initial load
library(lubridate) # for easy date manipulation
library(ggExtra) # because remembering ggplot theme options is beyond me
library(tidyr)
@johnmackintosh
johnmackintosh / blogyamlheaders.yml
Created January 14, 2017 21:09
yaml header template for blog posts
---
layout: post
published: false
title: #Insert title here
subtitle: #Insert sub here
tags:
- rstats
- R
- r-bloggers
date: '2017-01-02'
@johnmackintosh
johnmackintosh / wrapr let.R
Last active June 1, 2017 05:35
Investigating the wrapr let function
##### set up#######
library(dplyr)
library(wrapr)
data<-structure(list(Location = c("AreaZ", "AreaZ", "AreaZ", "AreaZ",
"AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ",
"AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ", "AreaZ",
## see http://johnmackintosh.com/2017-06-01-UPDATED-let-there-be-progress/ for background
#### direct from the expert - code kindly provided via blog comment by John Mount, Win-Vector LLC
library("dplyr")
library("wrapr")
d <- data.frame(
location = c('AreaZ', 'AreaZ', 'AreaZ', 'AreaW', 'AreaW', 'AreaW'),
@johnmackintosh
johnmackintosh / nhshsepsis.R
Last active November 7, 2017 18:27
trying out rtweet package R
library(rtweet)
library(tidyverse)
library(dplyr)
library(hrbrthemes)
library(extrafont)
library(viridis)
## create token named "twitter_token"
twitter_token <- create_token(
app = appname,
@johnmackintosh
johnmackintosh / case_when.R
Last active November 2, 2018 11:32
dplyr case_when syntax layout example
mutate( Movement_Type = case_when(
Type == "Transfer In" ~ "Transfer",
Type == "Transfer Out" ~ "Transfer"))
@johnmackintosh
johnmackintosh / fixings.r
Last active January 25, 2018 21:22
Data driven DIY decisions using R
library(readr)
library(ggplot2)
library(dplyr)
library(ggrepel)
data <- read_delim(
"Fixings.txt", "\t", escape_double = FALSE,
trim_ws = TRUE)