Skip to content

Instantly share code, notes, and snippets.

@cavedave
cavedave / Simon–Ehrlich wager
Last active November 22, 2020 15:44
When would Simon–Ehrlich wager be won by whom?
The Simon–Ehrlich wager was a 1980 scientific wager between business professor Julian L. Simon and biologist Paul Ehrlich, betting on a mutually agreed-upon measure of resource scarcity over the decade leading up to 1990
https://en.wikipedia.org/wiki/Simon%E2%80%93Ehrlich_wager
Roughly it was a bet where Simon thought things would get better as people invented and organised. Eldrich thought we would run out of stuff and overpopulation would result in starvation of hundreds of millions.
Simon won the bet as these metals were cheaper ten years later. But I wondered how ofter Simon would be rigth if the bet happened at different times.
Ten years later metals would be cheaper 55% of the time in this dataset.
Data from https://www.usgs.gov/centers/nmic/historical-statistics-mineral-and-material-commodities-united-states
@cavedave
cavedave / minmaxeng.r
Created August 14, 2020 17:24
Central England's Highest, Lowest and Average temp each year since 1878
library(tidyverse)
library(lubridate)
library(RCurl)
library(reshape2)
#URL <- "https://www.metoffice.gov.uk/hadobs/hadcet/cetmaxdly1878on_urbadj4.dat"
cet2 <- read.table("cetmaxdly1878on_urbadj4.dat.txt", sep = "", header = FALSE,
fill = TRUE)#),na.string = c(-99.99, -99.9, -999))
colnames(cet2) <- c("year","day","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
@cavedave
cavedave / snooker.r
Created August 12, 2020 11:49
Snooker breaks at world championship per year http://www.snooker.org/Plr/wc_centuries.shtml
breaks <- read.csv("breaks.csv", stringsAsFactors=FALSE)
breaks<-select (breaks,-c(X,X.1,X.2))
breaks<-na.omit(breaks)
names(breaks)[names(breaks) == "X."] <- "Centuries"
library(ggplot2)
# Basic scatter plot
g<-ggplot(breaks, aes(x=Year, y=Centuries)) +
geom_point(shape=1) + # Use hollow circles
geom_smooth(method=lm) +
historic<-read.csv("historic.csv", skip=10)
library(dplyr)
# Drop the columns of the dataframe
historic<-select (historic,-c(X.1,X.2,X.3,X.4,X.5,X.6,X.7,X.8,X.9,X.10,X.11))
historic <- rename(historic, number = Level..numbers.of.unemployed.people.) #For renaming dataframe column
historic <- rename(historic, rate = Rate....) #For renaming dataframe column
#start is nas
historic2<-slice(historic, 499:n())
@cavedave
cavedave / ElectionBar
Created February 9, 2020 11:31
Irish election bar chart
Cand <- c('Donnelly\n SF','Varadkar\n FG','Chambers\n FF','Coppinger\n SOL-PBP','O’Gorman\n Grn','Burton\n Lab')
per <- c(29, 18, 16,11,9,5)
part<-c("#CC0000","#660000","#66BB66","#326760","#99CC33","#009FF3")
df <- data.frame(Cand, per,part)
library(ggplot2)
# Basic barplot
p<-ggplot(data=df, aes(x=Cand, y=per, fill =part)) +
geom_bar(stat="identity", show.legend = FALSE)+scale_fill_manual(values=c("#CC0000","#660000","#66BB66","#326760","#99CC33","#009FF3"))+theme_minimal()+theme(plot.title = element_text(hjust = 0.5))
@cavedave
cavedave / dail.r
Last active February 3, 2020 14:25
Dáil Eireann seat map. using r package ggparliament. This code is based on this tutorial https://blog.mypad.in/creating-a-parliament-chart-in-r/
require(data.table)
require(tidyverse)
require(ggparliament)
irl<-read.csv("ireland.csv",header=1)
#colour column needs to be chr not factor
irl<-irl %>% mutate_if(is.factor, as.character)
irl_horseshoe <- parliament_data(election_data = irl,
party_seats = irl$seats,
@cavedave
cavedave / CountriesGates.csv
Last active January 22, 2020 22:07
World gdp growth rates by region
Country Continent random randomC
Algeria AFRICA 60.6167300016224 61
Angola AFRICA 71.5212095913241 72
Benin AFRICA 51.7624535957612 52
Botswana AFRICA 15.7730987774009 16
Burkina AFRICA 43.4650351116097 44
Burundi AFRICA 65.5623808542023 66
Cameroon AFRICA 50.6499306806902 51
Cape Verde AFRICA 13.4829147803843 14
Central African Republic AFRICA 17.8374229865049 18
@cavedave
cavedave / australiaheatmap.r
Last active January 15, 2020 00:51
heatmap of australian temperature records. data from http://www.bom.gov.au/climate/change/#tabs=Tracker&tracker=timeseries
library(dplyr)
library(ggplot2)
library(tidyr)
library(viridis)
library(scales)
library(ggthemes)
aus<-read.csv("latest.txt",sep=",",header=FALSE)
names(aus)[1] <- "time"
@cavedave
cavedave / genreloud.rmd
Last active February 17, 2025 16:55
Graph of how loud Music Genres are
---
title: "Loudness by Genre"
output: html_notebook
---
An analysis of music by Genre to see if loudness varies
It was believed that online streaming platform have reduced loudness. But does this have the same effect accross all genres of music?
@cavedave
cavedave / percentiles.r
Last active December 7, 2019 19:25
Code to make a stacked area chart of US wealth
data from https://www.federalreserve.gov/releases/z1/dataviz/dfa/distribute/table/#range:1989.3,2019.2;quarter:119;series:Net%20worth;demographic:networth;population:all;units:shares
```{r}
wealth<-read_csv("dfa-networth-shares.csv")
head(wealth)
```
```{r}