Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@briatte
briatte / crayola.R
Last active December 18, 2015 16:49
Crayola color vector for R
crayola <- structure(c("#EFDECD", "#CD9575", "#FDD9B5", "#78DBE2", "#87A96B",
"#FFA474", "#FAE7B5", "#9F8170", "#FD7C6E", "#000000", "#ACE5EE",
"#1F75FE", "#A2A2D0", "#6699CC", "#0D98BA", "#7366BD", "#DE5D83",
"#CB4154", "#B4674D", "#FF7F49", "#EA7E5D", "#B0B7C6", "#FFFF99",
"#1CD3A2", "#FFAACC", "#DD4492", "#1DACD6", "#BC5D58", "#DD9475",
"#9ACEEB", "#FFBCD9", "#FDDB6D", "#2B6CC4", "#EFCDB8", "#6E5160",
"#CEFF1D", "#71BC78", "#6DAE81", "#C364C5", "#CC6666", "#E7C697",
"#FCD975", "#A8E4A0", "#95918C", "#1CAC78", "#1164B4", "#F0E891",
"#FF1DCE", "#B2EC5D", "#5D76CB", "#CA3767", "#3BB08F", "#FEFE22",
"#FCB4D5", "#FFF44F", "#FFBD88", "#F664AF", "#AAF0D1", "#CD4A4C",
@briatte
briatte / cleaning_characters.r
Last active August 12, 2020 18:13
a few lines of code to load packages, download and scrape data, convert, sort, etc.
# removes characters from multiple data frame columns
# example removes * , % characters
dw <- data.frame(gsub("\\*|,|%", "", as.matrix(dw)), stringsAsFactors = FALSE)
@sheymann
sheymann / sigma.fruchterman.js
Created February 28, 2013 15:37
Fruchterman-Reingold layout plugin for Sigma.js with automatic cooling and stopping condition.
/**
* Linkurious 2012, all rights reserved.
* Sébastien Heymann <[email protected]>,
* Romain Yon <[email protected]>
*
* Please use http://jsbeautifier.org/ and indent with 2 spaces.
*
* Lib docs:
* http://twitter.github.com/bootstrap/
* http://docs.jquery.com/
@xmarquez
xmarquez / List-of-variables-ccp.csv
Last active December 12, 2015 09:39
Code for post on the Normativeness of Democracy
variable Question
cowcode Correlates of War country code (www.correlatesofwar.org).
country Country name.
systyear Year in which the constitutional system was promulgated.
systid Unique identification number for the constitutional system.
evntyear Year of promulgation of the most recent constitutional event.
endyear Year through which the data for the event is guaranteed valid.
evntid Unique identification number for the constitutional event.
evnttype Event type (e.g. amendment, new, etc.).
source What is the source for the text of the Constitution?
@chrishanretty
chrishanretty / pooling_spe.R
Created February 10, 2013 18:21
Pooling the polls for Italy, final version
### Takes as input a Google Docs spreadsheet
### Outputs national and regional level estimates of support
### over time
### Load libraries
library(R2WinBUGS)
library(rjags)
library(RCurl)
library(reshape)
library(foreach)
@jbryer
jbryer / parse.codebook.r
Last active March 9, 2023 15:19
Parses a codebook file where lines starting at column zero (far left) represet variable information (e.g. name, description, type) and indented lines (i.e. lines beginning with white space, either tabs or spaces, etc.) represent factor levels and labels.
#' Parse a codebook file with variable and level information.
#'
#' Parses a codebook file where lines starting at column zero (far left) represet
#' variable information (e.g. name, description, type) and indented lines
#' (i.e. lines beginning with white space, either tabs or spaces, etc.) represent factor
#' levels and labels.
#'
#' Note that white space at the beginning and end of each line is stripped before
#' processing that line.
#'
@dsparks
dsparks / latent_class_analysis.R
Created December 19, 2012 16:24
Latent class model of ANES respondents
doInstall <- TRUE
toInstall <- c("ggplot2", "poLCA", "reshape2")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
ANES <- read.csv("http://www.oberlin.edu/faculty/cdesante/assets/downloads/ANES.csv")
ANES <- ANES[ANES$year == 2008, -c(1, 11, 17)] # Limit to just 2008 respondents,
head(ANES) # remove some non-helpful variables
# Adjust so that 1 is the minimum value for each variable:
ANES <- data.frame(apply(ANES, 2, function(cc){ cc - min(cc, na.rm = T) + 1 }))
@dsparks
dsparks / tapered-intensity-curved_edges.R
Last active December 8, 2021 12:23
Beautiful tapered-intensity-curved edge network graph with ggplot2
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("sna", "ggplot2", "Hmisc", "reshape2")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Empty ggplot2 theme
new_theme_empty <- theme_bw()
new_theme_empty$line <- element_blank()
new_theme_empty$rect <- element_blank()
new_theme_empty$strip.text <- element_blank()
@chrishanretty
chrishanretty / cogsd7.R
Created November 20, 2012 14:26
Create replacement risk using ParlGov data
library(plyr)
library(zoo)
startyr <- 1992
endyr <- 2012
pg <- read.csv("http://www.parlgov.org/stable/static/data/stable-utf-8/view_cabinet.csv",as.is=T)
## Exclude GDR
pg <- pg[which(pg$country_name_short!="GDR"),]
@mbostock
mbostock / .block
Last active January 28, 2025 18:06 — forked from mbostock/.block
Choropleth
license: gpl-3.0
height: 600
border: no
redirect: https://beta.observablehq.com/@mbostock/d3-choropleth