Skip to content

Instantly share code, notes, and snippets.

View Pakillo's full-sized avatar
🌳
Living the dream

Francisco Rodriguez-Sanchez Pakillo

🌳
Living the dream
View GitHub Profile
@Pakillo
Pakillo / diverge0.R
Created December 12, 2019 13:44 — forked from johnbaums/diverge0.R
Plot a rasterVis::levelplot with a colour ramp diverging around zero
diverge0 <- function(p, ramp) {
# p: a trellis object resulting from rasterVis::levelplot
# ramp: the name of an RColorBrewer palette (as character), a character
# vector of colour names to interpolate, or a colorRampPalette.
require(RColorBrewer)
require(rasterVis)
if(length(ramp)==1 && is.character(ramp) && ramp %in%
row.names(brewer.pal.info)) {
ramp <- suppressWarnings(colorRampPalette(brewer.pal(11, ramp)))
} else if(length(ramp) > 1 && is.character(ramp) && all(ramp %in% colors())) {
@Pakillo
Pakillo / simulate.gamm.R
Created March 3, 2017 16:53 — forked from gavinsimpson/simulate.gamm.R
S3 method for simulate() for "gamm" objects from package mgcv
`simulate.gamm` <- function(object, nsim = 1, seed = NULL, newdata,
freq = FALSE, unconditional = FALSE, ...) {
if (!exists(".Random.seed", envir = .GlobalEnv, inherits = FALSE))
runif(1)
if (is.null(seed))
RNGstate <- get(".Random.seed", envir = .GlobalEnv)
else {
R.seed <- get(".Random.seed", envir = .GlobalEnv)
set.seed(seed)
RNGstate <- structure(seed, kind = as.list(RNGkind()))
@Pakillo
Pakillo / ShinyPerspectivePlot.R
Created December 19, 2016 10:08 — forked from leeper/ShinyPerspectivePlot.R
Shiny App for 3D Interaction plots
library("shiny")
library("shinyjs")
ui <- shinyUI(pageWithSidebar(
titlePanel("", "3D Perspective Plot for Interaction Effects"),
sidebarPanel(
tabsetPanel(
tabPanel("Data",
@Pakillo
Pakillo / beamer_two_col.Rmd
Created November 7, 2016 17:42 — forked from jhollist/beamer_two_col.Rmd
This .Rmd shows how to use two (or more) columns in a Beamer Presentation from RStudio
---
title: "Untitled"
author: "Jeff W. Hollister"
date: "2/2/2016"
output: beamer_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
@Pakillo
Pakillo / docx2md.md
Created January 11, 2016 14:21 — forked from jesperronn/docx2md.md
Convert a Word Document into MD

Converting a Word Document to Markdown in One Move

The Problem

A lot of important government documents are created and saved in Microsoft Word (*.docx). But Microsoft Word is a proprietary format, and it's not really useful for presenting documents on the web. So, I wanted to find a way to convert a .docx file into markdown.

Installing Pandoc

On a mac you can use homebrew by running the command brew install pandoc.

The Solution

@Pakillo
Pakillo / tables.Rmd
Created September 30, 2015 14:11 — forked from benmarwick/tables.Rmd
Methods for tables with rmarkdown
---
title: "A few methods for making tables in rmarkdown"
output: html_document
---
Updates:
Packages that have appeared since my original look into this, and seem great:
https://github.com/yihui/printr
### Title: Back to basics: High quality plots using base R graphics
### An interactive tutorial for the Davis R Users Group meeting on April 24, 2015
###
### Date created: 20150418
### Last updated: 20150423
###
### Author: Michael Koontz
### Email: mikoontz@gmail.com
### Twitter: @michaeljkoontz
###
@Pakillo
Pakillo / iwanthue.R
Last active April 4, 2020 22:34 — forked from johnbaums/iwanthue.R
swatch <- function(x) {
# x: a vector of colours (hex, numeric, or string)
par(mai=c(0.2, max(strwidth(x, "inch") + 0.4, na.rm = TRUE), 0.2, 0.4))
barplot(rep(1, length(x)), col=rev(x), space = 0.1, axes=FALSE,
names.arg=rev(x), cex.names=0.8, horiz=T, las=1)
}
# Example:
# swatch(colours()[1:10])
# swatch(iwanthue(5))
## Function to use GDAL to project coordinate reference system
# See http://www.gdal.org/gdalwarp.html for additional details
# `resampling` can be 'near' (nearest neighbour), 'bilinear', 'cubic', or
# 'lanczos' (Lanczos windowed sinc resampling).
# `extent` should be a bbox object or a vector of c(xmin, ymin, xmax, ymax)
# `of` is the output format (use GDAL short name as given by the name field of
# gdalDrivers(), or at http://www.gdal.org/formats_list.html)
# `extension` is the output extension corresponding to the primary file
# `ot` is the output type (see http://www.gdal.org/gdal_translate.html)
polygonizer <- function(x, outshape=NULL, gdalformat = 'ESRI Shapefile',
pypath=NULL, readpoly=TRUE, quietish=TRUE) {
# x: an R Raster layer, or the file path to a raster file recognised by GDAL
# outshape: the path to the output shapefile (if NULL, a temporary file will be created)
# gdalformat: the desired OGR vector format
# pypath: the path to gdal_polygonize.py (if NULL, an attempt will be made to determine the location
# readpoly: should the polygon shapefile be read back into R, and returned by this function? (logical)
# quietish: should (some) messages be suppressed? (logical)
if (isTRUE(readpoly)) require(rgdal)
if (is.null(pypath)) {