Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@briatte
briatte / dark_base16-tomorrow-night.rstheme
Created April 26, 2020 19:29 — forked from amandeepjutla/dark_base16-tomorrow-night.rstheme
RStudio theme: dark UI with base16 colors.
/* rs-theme-name: Dark UI Base16 Tomorrow Night */
/* rs-theme-is-dark: TRUE */
/* Dark UI from Randy3k's Wombat (https://github.com/randy3k/dotfiles/blob/master/.R/rstudio/themes/Wombat.rstheme) */
/* "Tomorrow night" color scheme adapted from chriskempson's Base16 (https://github.com/chriskempson/base16). */
.body {
background: #ffffff;
}
# triangle.py
import math
def triangle_perimeter(a, b, c):
return a + b + c
def triangle_area(a, b, c):
p = triangle_perimeter(a, b, c) / 2
x = math.sqrt(p * (p - a) * (p - b) * (p - c))
return round(x, 2)
# package dependency
library(haven)
path_in = "new_EB with more var_2004-2016.dta"
out_tsv = "new_EB.tsv"
out_sav = "new_EB.sav"
# name repair shows the issue with _merge
x = haven::read_dta(p, .name_repair = "universal")
names(x)[ names(x) == "._merge" ] = "MERGEVAR"
@briatte
briatte / example.r
Created February 11, 2015 15:10
testing https://github.com/kalimu/genderizeR with Finnish MP names
x = c("Aaltonen, Markus Sakari", "Stubb, Cai-Göran Alexander", "Ahde, Matti Allan",
"Saarakkala, Vesa-Matti", "Aho, Esko Tapani", "Piirainen, Raimo Olavi",
"Jääskeläinen, Pietari Osmo", "Juurikkala, Timo Johannes",
"Jokinen, Kalle Johannes", "Aho, Raila Orvokki", "Ahonen, Risto Sakari",
"Aittoniemi, Sulo Eerikki", "Ahvenjärvi, Sauli Sakari", "Mäkisalo-Ropponen, Merja Elina",
"Mäntylä, Hanna Katariina", "Autto, Heikki Samuli", "Ajo, Aimo Olavi",
"Mäntymaa, Markku Antero", "Mölsä, Martti Kullervo", "Niikko, Mika Ilari",
"Eerola, Juho Seppo Antero", "Eestilä, Markku Yrjö", "Packalén, Tom Erik",
"Elomaa, Ritva Tuulikki", "Pekonen, Aino-Kaisa Ilona", "Pelkonen, Jaana Maarit",
"Eloranta, Eeva-Johanna", "Donner, Jörn Johan", "Grahn-Laasonen, Sanni Kaisa",
@briatte
briatte / svyplot.ado
Last active September 19, 2019 10:17
svyplot -- a wrapper for catplot (Stata)
*! 0.2.3 F. Briatte 20mar2013
cap pr drop svyplot
program svyplot
syntax varlist(max=3) [if] [in] [aweight fweight iweight/] ///
[, Reds Blues Ascending Descending Horizontal Ymax(int 100) ///
Float(int 0) Size(real 3.5) ANGLE(int 0) NOPercent XLAb *]
// parse options
# Original by Kevin Ushey:
# https://raw.githubusercontent.com/kevinushey/etc/master/dotfiles/.Rprofile
.First <- function() {
# only run in interactive mode
if (!interactive())
return()
# create .Rprofile env
# change of PRNG in R >= 3.6.0
# use former PRNG
RNGkind(sample.kind = "Rounding")
# use new/fixed PRNG
RNGkind(sample.kind = "default")
# see ?Random for details
library(cartography)
library(sp)
# Load data
data(nuts2006)
# Get a SpatialLinesDataFrame of countries borders
nuts0.contig.spdf <- getBorders(nuts0.spdf)
# Get the GDP per capita
nuts0.df$gdpcap <- nuts0.df$gdppps2008/nuts0.df$pop2008*1000000
##
## download all `ergm` sources from v3.0-1 to today
##
library(rvest)
d <- "ergm-sources"
dir.create(d, showWarnings = FALSE)
# current source
@briatte
briatte / pairs_plot.R
Created May 8, 2019 13:40 — forked from expersso/pairs_plot.R
Create scatterplot matrix using the tidyverse
library(tidyverse)
library(patchwork)
plot_pair <- function(data, x, y) {
ggplot(data, aes_string(x = x, y = y, color = "Species", shape = "Species")) +
geom_point() +
scale_color_brewer(palette = "Dark2") +
theme(legend.position = "none", plot.title = element_text(size = 7)) +
labs(x = NULL, y = NULL, title = paste0(y, " ~ ", x))