Skip to content

Instantly share code, notes, and snippets.

View Rekyt's full-sized avatar

Matthias Grenié Rekyt

View GitHub Profile
@Rekyt
Rekyt / Franceggmap
Created November 5, 2014 17:29
ggmap basic use
library(ggmap)
sites = unique(df.table[, list(LON, LAT, interpreted.location, site.number)])
france = get_map("France", zoom = 6)
franceMap = ggmap(france)
franceMap +
geom_point(data = sites, aes(x = LON, y = LAT, color = as.factor(site.number)), size = 4) +
labs(x = "Longitude", y = "Latitude")
@Rekyt
Rekyt / GaussianPlot.R
Last active August 29, 2015 14:13
Rapid false gaussian plot with ggplot2
# Fast plot for gaussian function
#
library(ggplot2)
library(grid)
library(dplyr)
# Choose a window
seq = seq(-5, 5, 0.01)
# Compute density for Gaussian function
# Mean = 0, sd = 1
@Rekyt
Rekyt / multipageggplot2.R
Created March 12, 2015 18:17
Snippet to assemble ggplot2 plots over several PDF pages with gridExtra
# Multipage pdf plots with ggplot2
library(ggplot2) # Load ggplot2 obviously
library(gridExtra) # Load some extensions to have multiplot pdf
# Simulate data
df = data.frame(x = seq(1:30), y = rnorm(30), z = runif(30, 1, 10))
# Example plots
p.1 = ggplot(df, aes(x = x, y = y)) +
@Rekyt
Rekyt / ExampleAGR.R
Created April 22, 2015 17:57
Simulate traits data to show relations with growth
# Gist to simulate Growth Rate and Trait distribution
# Effects of varying coefficients
# Author: Matthias Grenié
# Packages ####
library(dplyr) # Manipulate data
library(gtools) # Combinations
library(ggplot2) # Plots
@Rekyt
Rekyt / asformula.R
Created May 20, 2015 20:14
Automatically generates formula based on df column names
# Example of automatic formula
# How to generate and test automatically different formulas
set.seed(1) # Makes it reproducible
library(dplyr)
library(lmerTest)
# Test data
df = data.frame(a = runif(30, 1, 10), b_sp = rnorm(30, 5, 20),
b_abs = runif(30, 0, 1), c_sp = rnorm(30, -3, 10),
@Rekyt
Rekyt / PointStroke_ggplot2
Created October 13, 2015 11:55
How to use the 'stroke' option of geom_point in ggplot2 R package
# For the moment, ggplot2 stable version cannot support the option 'geom_point(stroke = 2)' to change border size of points
# To use it we need to install ggplot2 development version
# To do that we first want to install 'devtools' package which makes packages installation from GitHub easier
install.packages("devtools")
# 'ggplot2' last version is at 'http://github.com/hadley/ggplot2/'
# thus using devtools' function 'install_github()' (install from GitHub) the syntax is simple:
devtools::install_github("hadley/ggplot2") # Note the use of '::' not to load the entire package
# Plots
@Rekyt
Rekyt / ConvexHull_ggplot2.R
Last active November 6, 2017 22:13
Draw convex hull for points in ggplot2
# Script to plot convex hull over points in ggplot2
# Packages
library(dplyr) # To make code easier to read
library(ggplot2)
# Data Generation
set.seed(1) # For reproducibility of example
df = data.frame(x = rnorm(100, 10, 5), y = rnorm(100, 10, 5), z = sample(letters[1:5], size = 100, replace = T))
@Rekyt
Rekyt / ColoredQuant_ggplot2.R
Last active August 30, 2017 04:00
Color Quantile from a density in ggplot2 with labeled quantiles
# Script from a density to color quantiles area
# Packages ---------------------------------------------------------------------
library(ggplot2)
library(dplyr)
# Data -------------------------------------------------------------------------
r_data = rnorm(100) # Computes 100 values
r_quant = quantile(r_data, probs = seq(0, 1, 0.1)) # Computes quantiles
@Rekyt
Rekyt / AlphaShape_ggplot2.R
Created November 4, 2015 20:58
Snippet to draw an alpha shape using ggplot2
# Script to plot an alpha shape on ggplot2 from a given sets of points
# Inspired by: https://rpubs.com/geospacedman/alphasimple
# Packages --------------------------------------------------------------------
library(ggplot2)
library(dplyr)
library(alphahull)
library(igraph)
@Rekyt
Rekyt / 365papers.md
Last active June 9, 2016 13:02
List of DOI of papers read in 2016

365 Papers

Using the #365papers hashtag on Twitter to show the list of papers read in 2016

List

  1. James H. Brown, "Macroecology", The University of Chicago Press, 1995;
  2. Mislan et al., "Elevating The Status of Code in Ecology", TREE, Jan 2016 https://doi.org/10.1016/j.tree.2015.11.006;
  3. Morueta-Holme, Blonder et al., "A network approach for inferring species associations from co-occurrence data", Ecography 22 January 2016, https://doi.org/10.1111/ecog.01892;
  4. Schuldt et al., "Multitrophic diversity in a biodiverse forest is highly nonlinear across spatial scales", Nature Communications, 10 Dec 2015, https://doi.org/10.1038/ncomms10169;