Skip to content

Instantly share code, notes, and snippets.

View pedroj's full-sized avatar
🌎
Fazendo ciência e soltando pipa

Pedro Jordano pedroj

🌎
Fazendo ciência e soltando pipa
View GitHub Profile
@pedroj
pedroj / Asset.R
Created March 25, 2013 16:31
Color-blind palettes
# The palette with grey:
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
# The palette with black:
cbbPalette <- c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
# To use for fills, add
scale_fill_manual(values=cbPalette)
# To use for line and point colors, add
@pedroj
pedroj / Asset.R
Created March 25, 2013 16:31
Reorder levels of a factor
## generate data
x = factor(sample(letters[1:5],100, replace=TRUE))
print(levels(x)) ## This will show the levels of x are "Levels: a b c d e"
## To reorder the levels:
## note, if x is not a factor use levels(factor(x))
x = factor(x,levels(x)[c(4,5,1:3)])
print(levels(x)) ## Now "Levels: d e a b c"
@pedroj
pedroj / Asset.R
Created March 25, 2013 16:29
basic ggplot scatter
ggplot() +
coord_cartesian() +
scale_x_continuous() +
scale_y_continuous() +
scale_color_hue() +
facet_wrap(~cut) +
layer(
data=diamonds,
mapping=aes(x=carat, y=price, color=color),
stat="identity",
@pedroj
pedroj / Asset.R
Created March 25, 2013 16:28
# ------- HEADER
# ----------------------------------------------------------------------------
# [Title]:
# [Date]: [Loc]:
# Pedro Jordano.
# ----------------------------------------------------------------------------
## First version __DATE__. Revised __DATE__
# ----------------------------------------------------------------------------
@pedroj
pedroj / bdiag.R
Created February 21, 2012 00:06
Function bdiag to build the canonical form of a matrix
######################################################################
# 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)
x <- lapply(x, function(y) if(length(y)) as.matrix(y) else
@pedroj
pedroj / cv_diff.R
Created February 21, 2012 00:03
Testing the difference between two CV's. From Example 8.12 in Zar, p. 144-145
#-----------------------------------------------------------------------------
# Testing the difference between two CV's
# From Example 8.12 in Zar, p. 144-145
#-----------------------------------------------------------------------------
w<-c(72.5,71.5,60.8,63.2,71.4,73.1,77.9,75.7,72.0,69.0)
h<-c(183.0,172.3,180.1,190.2,191.4,169.6,166.4,177.6,184.7,187.5,179.8)
#-----------------------------------------------------------------------------
# Testing the difference between two CV's
library(MBESS)
n1<-length(w); n2<-length(h)
@pedroj
pedroj / table_manip.txt
Created February 21, 2012 00:01
Table manipulation functions from a post by Campbell Webb
*******************************************************************
*** Solutions to a question I posted on the R-news mailing list ***
*** about simple table manipulation ***
*** Campbell Webb post in R-help ***
*******************************************************************
THE QUESTION:
Hi all,
@pedroj
pedroj / levyfunc.R
Created February 20, 2012 23:57
Function for Levy walk from source fixed point
#--------------------------------------------------------------------
# Function for Levy walk from source fixed point
# Pedro Jordano. 7 Apr 2009.
# Specify:
# R> levy(n,mu,l0)
# Where: n, is the number of events (default, n= 500)
# mu, is the Levy exponent (default, mu= 2.0)
# l0, is step size (default, l0= 1)
#--------------------------------------------------------------------
levy<-function (n= 500, mu= 2.0, l0= 1)
@pedroj
pedroj / levy.R
Created February 20, 2012 23:56
Lévy walk
##############################################################################
### LÉVY WALK CODE
#-----------------------------------------------------------------------------
library(adehabitat)
set.seed(411)
w <- simm.levy(1:500, mu = 1.5, burst = "mu = 1.5")
u <- simm.levy(1:500, mu = 2, burst = "mu = 2")
v <- simm.levy(1:500, mu = 2.5, burst = "mu = 2.5")
x <- simm.levy(1:500, mu = 3, burst = "mu = 3")
par(mfrow=c(2,2))
@pedroj
pedroj / readnet.R
Created February 20, 2012 23:47
Bulk read network data.
#################################################################
# Network analyses.
# Pedro. 7 Dec 2007
#################################################################
# NOTE: These matrices have rows are animals, columns are plants.
# NOTE: JORDI's datasets for NESTEDNESS have Rows are plants,
# columns are animals.
library(bipartite)
library(networksis)
library(igraph)