Skip to content

Instantly share code, notes, and snippets.

@cavedave
cavedave / Guinea Work Cases per Year
Last active March 9, 2016 21:39
Guinea Worm Cases by Year per Country
Guinea Worm Cases by Year per Country
#Package Wes Anderson colours R package https://github.com/karthik/wesanderson#wes-anderson-palettes
#His Box Office http://www.boxofficemojo.com/people/chart/?id=wesanderson.htm
#His IMDB http://www.imdb.com/name/nm0027572/
# wes csv is
#Name,IMDB,Earn,Year,Era
#The Grand Budapest Hotel,8.1,62,2014,later
#Moonrise Kingdom,7.8,50,2012,later
#Fantastic Mr. Fox,7.8,23,2009,mid
#The Darjeeling Limited,7.2,15,2007,mid
#The Life Aquatic with Steve Zissou,7.3,33,2004,mid
mydata = read.csv("output.csv", encoding="UTF-8", header=TRUE)
#book_id title rating num_ratings num_reviews book_id x.x x.y cover_rating
attach(mydata)
plot(rating,num_reviews,main="Number of Ratings Number Reviews")
cor(num_ratings,num_reviews)
> cor(num_ratings,num_reviews)
[1] 0.9597442
@cavedave
cavedave / balls.csv
Last active February 23, 2025 11:32
Use emoGG r package to make ggplot2 scatterplot with soccer ball geom_points
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Year Panels webpage name drag weight
1930 12 http://worldcupballs.info/world-cup-balls/1930-uruguay/1930-world-cup-ball-t-model.html
1934 13 http://worldcupballs.info/world-cup-balls/1934-italy/1934-world-cup-ball-federale-102.html
1938 13 http://worldcupballs.info/world-cup-balls/1938-france/1938-world-cup-ball-allen.html
1950 12 http://worldcupballs.info/world-cup-balls/1950-brazil/1950-world-cup-ball-superball.html
1954 18 http://worldcupballs.info/world-cup-balls/1954-switzerland/1954-world-cup-ball-swiss-world-champion.html
1958 24 http://worldcupballs.info/world-cup-balls/1958-sweden/1958-world-cup-ball-top-star.html
1962 18 http://worldcupballs.info/world-cup-balls/1962-chile/1962-world-cup-ball-crack.html
1966 25 http://worldcupballs.info/world-cup-balls/1966-england/1966-world-cup-ball-slazenger-challenge.html 14 - 16 ounces
1970 32
@cavedave
cavedave / WorldHeat.r
Last active May 19, 2020 19:00
Heatmap of world Temperature in r package for ggplot2
#This is inspired by this piral animation of the same dataset
#http://www.climate-lab-book.ac.uk/2016/spiralling-global-temperatures/
#and this R code to produce the animation
#https://gist.github.com/jebyrnes/b34930da0052a86f5ffe254ce9900357
# It also uses elements of this http://www.r-bloggers.com/making-faceted-heatmaps-with-ggplot2/
# and this https://rpubs.com/bradleyboehmke/weather_graphic graphic
library(dplyr)
library(tidyr)
library(ggplot2)
@cavedave
cavedave / scatterTemp.r
Created June 17, 2016 14:29
Englands temperature since 1659
#Dataset is cetml1659on.dat from hadcet [here](http://www.metoffice.gov.uk/hadobs/hadcet/data/download.html)
mydata = read.csv("cetml1659on.csv", header=TRUE)
gg<- ggplot(mydata, aes(x=Date, y=YEAR)) +
geom_point(shape=1) + # Use hollow circles
geom_smooth(method=lm)
plot.title = 'England Temperatures Since 1659'
plot.subtitle = 'HadCET Data. Correlation of Year and Temp .41 @iamreddave'
gg <- gg + ggtitle(bquote(atop(.(plot.title), atop(italic(.(plot.subtitle)), ""))))
@cavedave
cavedave / index.html
Last active July 4, 2016 16:38
Thousands of People Per Constituency Signing Petition for Another EURef
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>svg { position: relative; left: 315px; }</style>
</head>
<body>
<div id="frame"></div>
@cavedave
cavedave / index.html
Last active June 28, 2016 12:58
Hexbin Map of Irish Election Constituencies
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>svg { position: relative; left: 315px; }</style>
</head>
<body>
<div id="frame"></div>
install.packages("choroplethr")
install.packages("choroplethrMaps")
library(choroplethr);
library(choroplethrMaps)
library(ggplot2)
data(country.map)
data(country.regions)
a<-c(29,25,4,4,7,11,11,8,7,4,6,9,3,8,6,3,17,3,8,4,12,18,10,10,7,7,5,3,10,23,31,17,6,9,5,4,5,8,16,24,9)
@cavedave
cavedave / seaice.r
Last active February 7, 2025 18:43
#code is based on this animation https://gist.github.com/jebyrnes/b34930da0052a86f5ffe254ce9900357
#and this visualisation on this data http://www.realclimate.org/images/nsidc4.txt
#1. load libraries
library(dplyr)
library(tidyr)
library(ggplot2)
library(animation)
#2. get data in right format