Skip to content

Instantly share code, notes, and snippets.

@cavedave
cavedave / TrustVaccines
Created October 2, 2021 10:29
Do high trust countries have higher covid vaccination rates? Data from ourworldindata
trust <- read.csv("self-reported-trust-attitudes.csv",header=TRUE)
library(dplyr)
trust <- trust %>%
group_by(Entity) %>%
filter(Year == max(Year))
vac <- read.csv("owid-covid-data (1).csv",header=TRUE)
vac<-vac %>%
dplyr::select(people_vaccinated_per_hundred, location, date)
@cavedave
cavedave / vaccinewaffle.r
Created September 10, 2021 19:20
waffle graph of vaccination to ICU proportions
library(ggplot2)
library(waffle)
people <- c(`Vaccinated `=91,`Vaccinated in ICU`=1, `Unvaccinated`=7,
`Unvaccinated in ICU `=1)
waffle(people, rows=10, size=0.6,
colors=c("#44D2AC", "#E48B8B", "#B67093",
"#3A9ABD"),
title="Irish Adults",
df <-
readr::read_csv("https://projects.oregonlive.com/weather/pdx_temps.csv")
#Jun$Temp <- cut(Jun$tmax, breaks=c(50,104, Inf), labels=c("50","100+"))
Jun$Temp <- cut(Jun$tmax, breaks=c(50,60,70,80,90,100, Inf), labels=c("50","60","70","80","90","100+"))
hot <- c("#6BBCD1","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#b10026","#FF2A24")
#hot <- c("#000000","#FF2A24")
@cavedave
cavedave / cherry.r
Created March 30, 2021 22:06
visualisation of when cherry blossoms peak in kyoto
#data from https://datagraver.com/case/kyoto-cherry-blossom-full-flower-dates#google_vignette
df <- read.csv(file ="kyoto_dates_cherryblossom2021.csv")
library(tidyverse)
df<-df %>% drop_na()
library(lubridate)
df<-df %>% select(Year, Month, Day) %>%
mutate(date2 = make_date(Year, Month, Day))
df <- df %>%
mutate(dated = yday(date2))
Count Company Percentage of global industrial greenhouse gas emissions
1 China (Coal) 14.32%
2 Saudi Arabian Oil Company (Aramco) 4.50%
3 Gazprom OAO 3.91%
4 National Iranian Oil Co 2.28%
5 ExxonMobil Corp 1.98%
6 Coal India 1.87%
7 Petroleos Mexicanos (Pemex) 1.87%
8 Russia (Coal) 1.86%
9 Royal Dutch Shell PLC 1.67%
@cavedave
cavedave / Covid.r
Last active December 8, 2020 09:56
Picture comparing Covid fatalities to large battle deaths in the US
library(tidyverse)
library(lubridate)
library(scales)
#Data
#https://ourworldindata.org/coronavirus/country/united-states?country=~USA
#war https://en.wikipedia.org/wiki/List_of_battles_with_most_United_States_military_fatalities
df<-read.csv("daily-covid-deaths-7-day.csv", header=TRUE)
#Look at US
@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())