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
> # Simulate a dataset for the example | |
> modelflag <- 1 | |
> sim.dat <- PGLMM.sim(stree(16, "balanced"), nsites = 30, modelflag = modelflag, | |
+ second.env = TRUE, compscale = 1) | |
> sim.dat$Vphylo # I think this is the variance-covariance matrix from the phylogeny | |
t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 | |
t1 1.00 0.75 0.50 0.50 0.25 0.25 0.25 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 | |
t2 0.75 1.00 0.50 0.50 0.25 0.25 0.25 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 | |
t3 0.50 0.50 1.00 0.75 0.25 0.25 0.25 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 |
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
# Blog post about a new food web | |
> require(ggplot2); require(igraph); require(bipartite); require(NetIndices) | |
# read in edge list | |
> mygraph <- read.graph("/Mac/R_stuff/Blog_etc/newfoodweb/edgelist_new.txt", | |
+ format = "edgelist") | |
> str(mygraph) | |
List of 9 | |
$ : num 181 |
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
# Code from Liam Revell, and put up here by Scott Chamberlain | |
require(phytools); require(geiger) # load packages | |
ntaxa1<-20; ntaxa2<-2 # number of taxa in each clade | |
total.height<-10 # total tree height (may need to be adjusted) | |
# simulate subtree 1 | |
tr1<-birthdeath.tree(b=1,d=0,taxa.stop=ntaxa1) | |
tr1$tip.label<-1:ntaxa1; tr1$root.edge<-0 |
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
####################################################### | |
# by Scott Chamberlain <[email protected]> | |
# for blog post titled "Awesome use case: check my species names and | |
# gimme some distribution data" | |
####################################################### | |
# Load packages | |
install.packages(c("RCurl","stringr","XML","plyr","RJSONIO")) | |
require(RCurl);require(stringr);require(XML);require(plyr);require(RJSONIO) | |
# Clone taxize and rgbif repositories from GitHub |
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
require(plyr); require(stringr); require(ggplot2); require(lubridate); require(twitteR) | |
datout_1 <- searchTwitter("I work for the internet", n = 1500, since='2011-11-11', until='2011-12-12') | |
datout_2 <- searchTwitter("I work for the internet", n = 1500, since='2011-11-13', until='2011-12-14') | |
datoutdf <- ldply(c(datout_1, datout_2), function(x) x$toDataFrame(), .progress="text") | |
actual <- grep("I work for the internet", datoutdf[,1], ignore.case=T) | |
datoutdf2 <- datoutdf[actual,] | |
datoutdf2$newtime <- round_date(datoutdf2[,4], "hour") |
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
piechart <- function(set) { | |
ggplot(dat[dat$type==set,], aes(x = "", y = pageviews, fill = name)) + | |
theme_bw() + | |
geom_bar(width = 1) + | |
coord_polar(theta = "y") + | |
labs(y="", x='') + | |
opts(panel.border = theme_rect(colour = 'white'), | |
axis.text.x = theme_text(colour='white')) | |
} |
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
# setwd("/Mac/R_stuff/Blog_etc/Mammal_Dataset") | |
# URLs for datasets | |
comm <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_communities.csv" | |
refs <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_references.csv" | |
sites <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_sites.csv" | |
spp <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_species.csv" | |
trap <- "http://esapubs.org/archive/ecol/E092/201/data/MCDB_trapping.csv" | |
# read them |
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
library(reshape2) | |
library(ggplot2) | |
dataset <- data.frame(var1 = rep(c("a","b","c","d","e","f"), each = 4), | |
var2 = rep(c("level1","level1","level2","level2"), 6), | |
var3 = rep(c("h","m"), 12), meas = rep(1:12)) | |
Created by Pretty R at inside-R.org | |
# simply pivot table | |
dcast(dataset, var1 ~ var2 + var3) |
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
# Define the function | |
loghistplot <- function(data) { | |
require(ggplot2); require(gridExtra) # load packages | |
names(data) <- c('x','y') # rename columns | |
# get min and max axis values | |
min_x <- min(data$x) | |
max_x <- max(data$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
# calculate tree resolution stats | |
treeresstats <- function(x) { | |
require(phangorn) # load the phangorn package | |
todo <- ( 1+Ntip(x)) : (Ntip(x) + Nnode(x) ) | |
trsize_tips <- Ntip(x) | |
trsize_nodes <- Nnode(x) | |
polytomyvec <- sapply(todo, function(y) length(Children(x, y))) | |
numpolys <- length(polytomyvec[polytomyvec > 2]) | |
numpolysbytrsize_tips <- numpolys/trsize_tips | |
numpolysbytrsize_nodes <- numpolys/trsize_nodes |