This file contains 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
SankeyR <- function(inputs, losses, unit, labels, format="plot"){ | |
######################## | |
# SankeyR version 1.01 (updated August 10, 2010) | |
# is a function for creating Sankey Diagrams in R. | |
# See http://www.sankey-diagrams.com for excellent examples of Sankey Diagrams.ç | |
# This is based on a Gist by https://gist.github.com/aaronberdanier | |
# | |
# OPTIONS: | |
# 'inputs' is a vector of input values | |
# 'losses' is a vector of loss values |
This file contains 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
source_https <- function(url, ...) { | |
# load package | |
require(RCurl) | |
# parse and evaluate each .R script | |
sapply(c(url, ...), function(u) { | |
eval(parse(text = getURL(u, followlocation = TRUE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))), | |
envir = .GlobalEnv) | |
}) | |
} |
This file contains 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
# Multiple plot function | |
# | |
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects) | |
# - cols: Number of columns in layout | |
# - layout: A matrix specifying the layout. If present, 'cols' is ignored. | |
# | |
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), | |
# then plot 1 will go in the upper left, 2 will go in the upper right, and | |
# 3 will go all the way across the bottom. | |
# |
This file contains 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
mytheme_bw <- function (base_size = 12, base_family = "") | |
{ | |
theme_grey(base_size = base_size, base_family = base_family) %+replace% | |
theme(axis.text = element_text(size = rel(0.8)), | |
axis.ticks = element_line(colour = "black"), | |
legend.key = element_rect(colour = "grey80"), | |
panel.background = element_rect(fill = "white", colour = NA), | |
panel.border = element_rect(fill = NA, colour = "black"), | |
panel.grid.major = element_line(colour = "grey90", size = 0.2), | |
panel.grid.minor = element_line(colour = "grey98", size = 0.4), |
This file contains 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
#!/bin/bash | |
############################################################################## | |
# Name: templateR.sh | |
# Author: Frank Farach | |
# Description: Script to clone templateR repo from GitHub account, | |
# with options to name the local working directory and RStudio | |
# project. This depends on the existence of a repository called templateR | |
# in the GitHub account of user named in the global variable USER below. | |
# See: http://github.com/frankfarach/templateR |
This file contains 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]: Functions to generate adjacency matrix fills useful in | |
# network analysis. | |
# [Date]: 1 Apr 2013 [Loc]: Sevilla | |
# Pedro Jordano. | |
# ...................................................................... | |
# nullmat will generate a 0 matrix of size m x n. | |
# fullconnmat will generate a fully-connected matrix of size m x n. | |
# randommat will generate a randomly-filled matrix of size m x n. | |
# fullynest will generate a fully-nested matrix of size m x n. |
This file contains 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
################################################################################ | |
# Illustration of the Small-world property in the Watts-Strogatz model. | |
#------------------------------------------------------------------------------- | |
library(igraph) | |
set.seed(1) | |
avg.stat <- function(nei, p) { | |
result <- replicate(1000, { | |
wsg <- watts.strogatz.game(1, 100, nei, p) | |
c(average.path.length(wsg), |
This file contains 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
###################################################################### | |
# Function bdiag to build the canonical form of a matrix | |
###################################################################### | |
# Pedro Jordano. 18 Dic 2007. | |
###################################################################### | |
bdiag <- function(x){ | |
if(!is.list(x)) stop("x not a list") | |
n <- length(x) | |
if(n==0) return(NULL) |
This file contains 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
# Parameters | |
# Function to estimate network parameters. | |
require(bipartite) | |
params <- function(mat) | |
# Obtain basic parameters from an interaction matrix | |
# From library(bipartite) functions. We are getting just 8 indexes. | |
{networklevel(mat, #tapis | |
index=c(# "species", | |
"connectance", #1-C | |
"web asymmetry", #2-WA |
This file contains 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
######################################################### | |
# Getting the pairwise interactions list | |
# Format: "Pant.species-Animal.species" | |
# assocs is a matrix (AxP). With rownames and colnames. | |
# | |
# pairwise(t(assocs)) will give the interactions list | |
# as: "Animal.species-Pant.species" | |
# Pedro Jordano. Sevilla - 15 Abr 2006 02:13:45. | |
#-------------------------------------------------------- | |
pairwise<-function(assocs) { |
NewerOlder