Skip to content

Instantly share code, notes, and snippets.

View Rekyt's full-sized avatar

Matthias Grenié Rekyt

View GitHub Profile
@Rekyt
Rekyt / DensityQuantile_ggplot2.R
Created January 13, 2016 10:59
plot of density of a given vector of numbers with quantile areas colored
# Script to make a plot of density of a given vector of numbers with quantile
# areas colored
# Package -------------------------------------------------------------------
library(ggplot2)
library(dplyr)
# Function ------------------------------------------------------------------
make_quantile_density = function(ex_vector, probs = NULL) {
@Rekyt
Rekyt / mat_dist.R
Last active January 21, 2016 12:50
Matrix Indices Computation
# Matrix of presence-absence
m = structure(c(1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1), .Dim = c(4L,
4L), .Dimnames = list(c("a", "b", "c", "d"), c("site1", "site2",
"site3", "site4")))
# Distance matrix
dist = structure(c(0, 0.2, 0.7, 0.33, 0.2, 0, 0.5, 0.15, 0.7, 0.5, 0,
0.23, 0.33, 0.15, 0.23, 0), .Dim = c(4L, 4L), .Dimnames = list(
c("a", "b", "c", "d"), c("a", "b", "c", "d")))
@Rekyt
Rekyt / Non_random_selection.R
Created January 22, 2016 17:48
Function that has a biased selection
# Example of a function that creates a biased distribution
# Packages --------------------------------------------------------------------
library(ggplot2)
# Constants -------------------------------------------------------------------
data_size = 10000
test_index = 10
@Rekyt
Rekyt / Rsq.R
Last active February 23, 2016 14:26
R squared for list of Mixed models
# Compute R squared from a list of computed and selected models
# Packages ---------------------------------------------------------------------------------------
library(MuMIn)
# Fit general model ------------------------------------------------------------------------------
global_mod = lm(mpg ~ ., data = mtcars)
@Rekyt
Rekyt / ggplot2_stat_qq.R
Created March 30, 2016 13:59
Use of stat qq to plot qqplots in ggplot2
# List of qqplots using 'apply()' function
#
library(ggplot2)
data(mtcars)
plot_list = apply(mtcars, 2, function(line) {
my_plot = ggplot(data.frame(x = line), aes(sample = x)) +
stat_qq() +
@Rekyt
Rekyt / map_ggplot2.R
Created August 19, 2016 13:37
Create map with ggplot2
# Create a map with ggplot2
# Packages
library(ggplot2)
library(ggmap)
# Get France base map (using 'ggplot2::map_data()' function)
france_map = map_data("france")
# Get cities longitude and latitude (using 'ggmap::geocode()' function)
cities = c("Montpellier", "Rouen", "Poil")
@Rekyt
Rekyt / add_groups.R
Created August 26, 2016 12:48
From kruskal() in agricolae package add groups to a plot
# Add groups from a multiple kruskal wallis test
add_groups = function(given_plot, ks_tests) {
y_range = ggplot_build(given_plot)$panel$ranges[[1]]$y.range
y_upper = max(y_range)
group_df = ks_tests$groups %>%
select(trt, M) %>%
mutate(y = y_upper)
group_df$trt = factor(trimws(group_df$trt), levels = iucn_groups)
@Rekyt
Rekyt / phylo_trait.R
Created September 6, 2016 11:56
plot trait values at the tip of phylogeny
# Script to add a trait matrix over a circular phylogenetic tree
# Packages ---------------------------------------------------------------------
library(ape)
library(ggtree)
# Generate Tree and Traits -----------------------------------------------------
@Rekyt
Rekyt / microbenchmark_uneval.R
Created February 17, 2017 12:20
Compare speed of functions with across parameter range
# Programmatically use 'microbenchmark()'
# Author: Matthias Grenié
library(microbenchmark)
# Get two functions
my_func = function(x) {
5^x
}
@Rekyt
Rekyt / creating_eml.Rmd
Created March 9, 2017 12:35
Thoughts on creating EML
---
title: "Writing EML files"
author: "Matthias Grenié"
date: "9 mars 2017"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```