Skip to content

Instantly share code, notes, and snippets.

@cavedave
cavedave / cherry.r
Created Mar 30, 2021
visualisation of when cherry blossoms peak in kyoto
View cherry.r
#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))
View Carbon.csv
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 Dec 8, 2020
Picture comparing Covid fatalities to large battle deaths in the US
View Covid.r
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 Nov 22, 2020
When would Simon–Ehrlich wager be won by whom?
View Simon–Ehrlich wager
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 Aug 14, 2020
Central England's Highest, Lowest and Average temp each year since 1878
View minmaxeng.r
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 Aug 12, 2020
Snooker breaks at world championship per year http://www.snooker.org/Plr/wc_centuries.shtml
View snooker.r
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) +
View unemploymentUK.r
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 Feb 9, 2020
Irish election bar chart
View ElectionBar
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 Feb 3, 2020
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/
View dail.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 Jan 22, 2020
World gdp growth rates by region
View CountriesGates.csv
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