This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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"))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example of a function that creates a biased distribution | |
| # Packages -------------------------------------------------------------------- | |
| library(ggplot2) | |
| # Constants ------------------------------------------------------------------- | |
| data_size = 10000 | |
| test_index = 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Compute R squared from a list of computed and selected models | |
| # Packages --------------------------------------------------------------------------------------- | |
| library(MuMIn) | |
| # Fit general model ------------------------------------------------------------------------------ | |
| global_mod = lm(mpg ~ ., data = mtcars) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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() + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Script to add a trait matrix over a circular phylogenetic tree | |
| # Packages --------------------------------------------------------------------- | |
| library(ape) | |
| library(ggtree) | |
| # Generate Tree and Traits ----------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Programmatically use 'microbenchmark()' | |
| # Author: Matthias Grenié | |
| library(microbenchmark) | |
| # Get two functions | |
| my_func = function(x) { | |
| 5^x | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| title: "Writing EML files" | |
| author: "Matthias Grenié" | |
| date: "9 mars 2017" | |
| output: pdf_document | |
| --- | |
| ```{r setup, include=FALSE} | |
| knitr::opts_chunk$set(echo = TRUE) | |
| ``` |