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;
}
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
@briatte
briatte / gist:ad24bb323d2603dbdd3af35086147c83
Created May 18, 2019 05:43 — forked from conormm/r-to-python-data-wrangling-basics.md
R to Python: Data wrangling with dplyr and pandas
R to python useful data wrangling snippets
The dplyr package in R makes data wrangling significantly easier.
The beauty of dplyr is that, by design, the options available are limited.
Specifically, a set of key verbs form the core of the package.
Using these verbs you can solve a wide range of data problems effectively in a shorter timeframe.
Whilse transitioning to Python I have greatly missed the ease with which I can think through and solve problems using dplyr in R.
The purpose of this document is to demonstrate how to execute the key dplyr verbs when manipulating data using Python (with the pandas package).
dplyr is organised around six key verbs
@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))
@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)
}
---
title: "World maps"
output:
html_document:
df_print: paged
---
```{r echo = FALSE, message = FALSE}
library(tidyverse)
library(sf)
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
@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,
@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 / 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()