Skip to content

Instantly share code, notes, and snippets.

@baptiste
baptiste / filter.lua
Last active April 12, 2019 20:47
pandoc --lua-filter filter.lua test.md -o test.docx
-- we use preloaded text to get a UTF-8 aware 'upper' function
local text = require('text')
function RawInline(el)
if el.format == 'tex' then
newcode = el.text:gsub('\\code', '')
return pandoc.SmallCaps(newcode)
end
end
@baptiste
baptiste / hanging.Rmd
Created April 14, 2019 00:33
fixed width plot panel, rest hanging in margins
---
title: "Title"
header-includes:
- \usepackage{lipsum}
output:
pdf_document:
fig_caption: yes
fig_crop: no
keep_tex: yes
geometry: width=5in
library(rmarkdown)
pre_knit <- function(input, ...){
rd <- readLines(input)
id <- grep('◊', rd)
rd[id] <- stringr::str_replace_all(rd[id],
"`◊([:alnum:]+)\\((.*?)\\)`",
replacement = '`r \\1("\\2")`')
file.copy(input, paste0(input, 'original.Rmd'))
writeLines(text = rd, con = input)
@baptiste
baptiste / fixedar.r
Last active December 4, 2019 19:26
library(ggplot2)
set.seed(1221)
dat <- data.frame(x=rnorm(100), y=rnorm(100), type=rep(1:2, each=50))
p <- ggplot(dat) + geom_point(aes(x, y)) +
facet_wrap(~type) + coord_fixed() +
theme(plot.background = element_rect(fill='red'))
# inspired by
# egg::set_panel_size
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
library(leaflet)
library(rayshader)
library(raster)
library(geoviz)
# define bounding box with longitude/latitude coordinates
bbox <- list(
p1 = list(long = 172, lat = -41.0),
p2 = list(long = 173.1, lat = -40.4)
)
library(egg)
library(gridExtra)
library(ggplot2)
library(grid)
d <- data.frame(x=runif(10*7),
y=runif(10*7),
f1 = gl(7,10),
f2 = gl(3, 30, 7*10))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@baptiste
baptiste / craft.R
Created February 22, 2020 22:51
hand-crafted hard-coded ggplot
library(glue)
make_header <- function(css = 'svg.css')
glue(
'<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="{css}"?>
<svg viewBox="0 0 576 216" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">', css = css)
make_defs <- function()
'
library(ggplot2)
library(egg)
library(extrafont)
library(xkcd)
library(grid)
d <- data.frame(x=rep(-1:1,3),y=0,facet=rep(1:3,each=3))
p0 <- ggplot(d, aes(x,y)) +
facet_wrap(~facet, labeller = label_both) +