Skip to content

Instantly share code, notes, and snippets.

@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 December 6, 2019 17:57
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}
#load the libraries
library(ggplot2)
library(grid)
library(dplyr)
#load the data
#https://public.opendatasoft.com/explore/dataset/us-zip-code-latitude-and-longitude/export/
zips <-
read.csv("us-zip-code-latitude-and-longitude.csv",
header = TRUE, stringsAsFactors = TRUE,sep=";")
@cavedave
cavedave / Martin-Quinn.r
Created November 15, 2019 19:32
Martin-Quinn scores for justices, 1937-2018. The r package ggplot2 code is very slightly modified version of https://rud.is/b/2016/06/28/making-time-rivers-in-r/ by https://twitter.com/hrbrmstr data from https://mqscores.lsa.umich.edu/measures.php This made the reddit front page in a slightl different version https://www.reddit.com/r/dataisbeaut…
```{r}
library(dplyr)
library(readr)
library(ggplot2) # devtools::install_github("hadley/ggplot2")
#library(hrbrmisc) # devtools::install_github("hrbrmstr/hrbrmisc")
library(grid)
library(scales)
library(grid)
@cavedave
cavedave / CenterUKVoting.r
Created November 3, 2019 09:37
Make a map of where people in the UK vote
Now start with maps and locations
See if i can get the center of constituencies
data from https://geoportal.statistics.gov.uk/datasets/westminster-parliamentary-constituencies-december-2017-super-generalised-clipped-boundaries-in-the-uk/data
```{r}
locat<-read_csv("Westminster_Parliamentary_Constituencies_December_2017_Super_Generalised_Clipped_Boundaries_in_the_UK.csv")#, sheet = 2, skip=6 , header=TRUE
head(locat)
@cavedave
cavedave / ukelection.Rmd
Last active November 1, 2019 22:38
UK election visualisations
---
title: "uk election"
output: html_notebook
---
Inspired by this great graph by Alasdair Rae
https://twitter.com/undertheraedar/status/1190192038274310144 i want to make an election visualisation
data from https://commonslibrary.parliament.uk/parliament-and-elections/elections-elections/constituency-data-election-results/
```{r}