Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@briatte
briatte / NEET-in-Europe.R
Created July 19, 2017 16:40 — forked from ikashnitsky/NEET-in-Europe.R
Young people neither in employment nor in education and training in Europe, 2000-2016
################################################################################
#
# ikashnitsky.github.io 2017-07-18
# Accessing Eurostat data using the `eurostat` R package
# Young people neither in employment nor in education and training in Europe
# Ilya Kashnitsky, [email protected]
#
################################################################################
# Erase all objects in memory
@briatte
briatte / vpt.R
Created August 2, 2017 08:26 — forked from chrishanretty/vpt.R
Replicating Angelova et al., "Veto player theory and reform making in Western Europe"
library(MASS)
library(rio)
library(tidyverse)
multhet <- function(y, ## = formula(1~1),
v, ## = formula(~1),
data) {
## check length of inputs
if (class(y) != "formula") {
@briatte
briatte / terrorism-in-ukg-1970-2015.R
Created August 23, 2017 14:16 — forked from svmiller/terrorism-in-ukg-1970-2015.R
Model terrorism patterns in the United Kingdom
# You won't need all of these packages. I just copied it from another,related analysis:
# https://github.com/svmiller/etjc
library(car)
library(arm)
library(countrycode)
library(data.table)
library(tidyverse)
library(sqldf)
# library(pdftools)
@briatte
briatte / canny.R
Created August 28, 2017 15:39 — forked from jeroen/canny.R
Magick canny edge detector
library(magrittr)
library(magick)
image_read("logo:") %>%
image_convert('png', colorspace = 'gray') %>%
image_edge(radius = 1) %>%
image_negate() %>%
image_transparent('white', 10000) %>%
image_background("white") %>%
image_browse()
@briatte
briatte / userChrome.css
Created November 18, 2017 09:47 — forked from johngruen/userChrome.css
kill drag space
/*
Create a userChrome.css file by finding your Firefox profile,
making a directory called chrome and in it, a file called userChrome.css inside that.
Pasting this CSS and restarting Firefox will kill the left drag strip
*/
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
.titlebar-placeholder[type="pre-tabs"] {
width: 2px !important;
@briatte
briatte / segmented_brexit.R
Created January 17, 2018 03:44 — forked from chrishanretty/segmented_brexit.R
Segmented regression on Brexit Right-Wrong gap
library(segmented)
library(tidyverse)
dat <- structure(list(Pollster = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Poll by gfk",
"Poll by YouGov"), class = "factor"), Fieldwork.end.date = structure(c(17539,
17520, 17511, 17505, 17478, 17463, 17459, 17458, 17450, 17433,
17409, 17400, 17379, 17366, 17358, 17339, 17330, 17324, 17317,
library(rvest)
library(lubridate)
library(tidyverse)
Truman <- read_html("http://www.presidency.ucsb.edu/data/popularity.php?pres=33")
Truman %>%
html_table(fill=T) -> Truman
Truman[[11]] -> Truman
---
title: "World maps"
output:
html_document:
df_print: paged
---
```{r echo = FALSE, message = FALSE}
library(tidyverse)
library(sf)
@briatte
briatte / label_facets_ggplot2.R
Created January 9, 2019 01:57 — forked from padpadpadpad/label_facets_ggplot2.R
function to label facets with letters in ggplot2
# load package
library(ggplot2)
# write function
label_facets <- function(string){
len <- length(string)
string = paste('(', letters[1:len], ') ', string, sep = '')
return(string)
}
@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))