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
# Install R latest version: https://cloud.r-project.org/
# For installing R on Linux, check out https://docs.rstudio.com/resources/install-r/
# Instructions: https://moderndive.netlify.app/1-getting-started.html
# Install RStudio latest version: https://www.rstudio.com/products/rstudio/download/#download
# Open RStudio and install some R packages using the code below:
install.packages(c(
"tidyverse",
@Pakillo
Pakillo / GLM_course_install.R
Last active August 26, 2021 15:22
GLM course: packages to install
# Install R latest version: https://cloud.r-project.org/
# Install RStudio latest version: https://www.rstudio.com/products/rstudio/download/#download
# Install R packages below:
install.packages(c(
"rmarkdown",
"knitr",
"dplyr",
@Pakillo
Pakillo / biscale_raster_map.md
Last active July 21, 2021 08:15
Using {biscale} package to plot bivariate raster maps in R
## Using {biscale} to plot bivariate raster maps

library(ggplot2)
library(biscale)
library(cowplot)
library(raster)
#> Loading required package: sp
@Pakillo
Pakillo / install.R
Last active June 7, 2021 10:14
BLIZ Summer School - software & R packages to install
# Install R latest version: https://cloud.r-project.org/
# Install RStudio latest version: https://www.rstudio.com/products/rstudio/download/#download
# Install R packages below:
install.packages("remotes")
install.packages("workflowr")
remotes::install_github("benmarwick/rrtools")
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)) {
@Pakillo
Pakillo / tiempo_vs_clima.R
Created January 11, 2021 20:23
Tiempo vs Clima - Weather vs Climate
library(ggplot2)
t <- 1:100 # create time sequence
# warming trend, constant variance
clima <- data.frame(t = t,
temp = rnorm(100, 15 + 0.03*t, sd = 1))
# warming trend + increasing variance
clima <- data.frame(t = t,
@Pakillo
Pakillo / separate_bibliographies.Rmd
Last active December 29, 2020 22:42
Having separate reference lists in a Rmarkdown document
---
title: "Having separate reference lists in an Rmarkdown document"
author: "F. Rodriguez-Sanchez"
output:
github_document:
pandoc_args: --lua-filter=multiple-bibliographies.lua
bibliography_main: main.bib
bibliography_suppl: suppl.bib
---
@Pakillo
Pakillo / gist:02bc9c52246559d266ff5d5ef6d374b8
Last active October 7, 2020 12:59
How to hide some slides in Rmarkdown-generated beamer PDF presentation
https://stackoverflow.com/a/58679929
See also
http://latex-beamer-class.10966.n7.nabble.com/Hiding-frames-td907.html
https://tex.stackexchange.com/questions/200151/remove-frame-from-presentation
https://tex.stackexchange.com/questions/200151/remove-frame-from-presentation
@Pakillo
Pakillo / word-character-count-Rstudio.md
Last active June 25, 2020 21:24
Count words and characters in Rstudio

As far as I know Rstudio does not count words or characters at the moment, which would be useful particularly when writing Rmarkdown.

This is a quick shortcut using word_count and character_count functions from qdap package. See below for two wrapper functions that simplify their use.

library("qdap")

Just select and copy the text to the clipboard and then run in the console:

@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))