Skip to content

Instantly share code, notes, and snippets.

@baptiste
baptiste / just-table.R
Last active June 25, 2018 22:41
justifying tables with annotation_custom
library(ggplot2)
library(egg)
library(gridExtra)
library(grid)
justify <- function(x, hjust="center", vjust="center", draw=FALSE){
w <- sum(x$widths)
h <- sum(x$heights)
xj <- switch(hjust,
center = 0.5,
#!/bin/bash
pbpaste | highlight -O rtf -S $1 -u UTF8 -k Source\ Sans\ Pro -K 32 -s github | pbcopy
delayedAssign('open', {
system('open .')
getwd()
})
---
title: Wizard • pointy-hatted • pipe smoker
author: gandalf the grey
alsoknown: Olórin, Gandalf
nationality: Maia, bearer of Narya
age: Born before Arda was created
date: third age
address: Valinor, Arda
mobile: "`flying moths`"
email: "`[email protected]`"
@baptiste
baptiste / graph paper.tex
Created August 19, 2018 05:47 — forked from mcnees/graph paper.tex
Make your own quadrille, graph, hex, etc paper! Uses the pgf/TikZ package for LaTeX, which should be part of any modern TeX installation.
%%-----------------------------------------------------------------------
%% Make your own quadrille, graph, hex, etc paper!
%% Uses the pgf/TikZ package for LaTeX, which should be part of
%% any modern TeX installation.
%% Email: [email protected]
%% Twitter: @mcnees
%%-----------------------------------------------------------------------
\documentclass[11pt]{article}
@baptiste
baptiste / chem.R
Last active September 18, 2018 09:39
library(ggplot2)
library(gridExtra)
library(grid)
library(tikzDevice)
chem <- "\\setatomsep{1em}\\chemfig{*6(-=-=(-[:90]N-[:30](=[:90]O)-[:-30](=[:-90]O)-[:30]N-[:-30]-[:30]-[:-30]N-[:30](=[:90]O)-[:-30](=[:-90]O)-[:30]N-[:-30](-[:-90]-[:-30](-[:30])-[:-90])-[:30](=[:90]O)-[:-30]O-[:30])-*6(-(=O)-*6(-=-=-=)--(=O)-)=)}"
p <- ggplot() + xlab('some chemistry') + ylab("some value") +
theme(plot.background = element_rect(colour = 'black', fill=NA),
@baptiste
baptiste / tg.R
Created September 23, 2018 20:30
library(gridExtra)
library(grid)
library(gtable)
d <- iris[1:2,1:3]
g <- tableGrob(d, rows=NULL)
grid.newpage()
grid.draw(g)
@baptiste
baptiste / sf.R
Last active September 25, 2018 08:04
library(sf)
# sf::st_layers('zzz.gpx')
a <- sf::st_read('zzz.gpx', 'track_points')
cbind(sf::st_coordinates(a), a$ele)
st_bbox(a)
a %>% mapview:: mapview(a)
library(tikzDevice)
library(ggplot2)
options(tikzLatexPackages =
c(getOption('tikzLatexPackages'),"\\usepackage{graphics}\n"))
d = data.frame(x=1:10, y=1:10, f=factor(sample(letters[1:2], 10, repl=TRUE)))
p <- qplot(x,y,data=d) + theme_bw() +
theme(plot.margin = unit(c(1, 1, 5, 1), "lines"),
axis.text.x = element_text(size = 12 *
fun_labels <- function(x) sprintf("<b>%s</b>", x)
ggplot() +
scale_x(breaks = c('a','b','c')) +
theme(axis.label = element_sticker(grob = fancyGrob, dictionary = fun_labels))
my_labels <- tibble(label = letters[1:3], grobs = I(lapply(1:3, fancyGrob)))