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
###############Food web plotting function################ | |
### Date: 12/13/2011 | |
### Author: Edmund Hart ([email protected]) | |
### Description: A function to create grahps of trophic networks using ggplot2 | |
### Plots food webs in a circular graph | |
### requires ggplot2 | |
######################################################### | |
library(ggplot2) | |
########## support function create.xy |
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
x <- seq(-4,4,length=1000) | |
y <- dnorm(x,0,1) | |
plot(x,y,type='l',ylim=c(0,.5)) | |
###Set the lower limits of interest | |
ll <- -1 | |
ul <- 1 | |
######Hit and miss MC integration##### | |
###First pick domain | |
x.dom <- seq(-4,4,length=1000) | |
y.dom <- seq(0,.5,length=1000) |
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
###Example 1 | |
# Simple test of difference of two means | |
#### | |
#############Note I do some plots in regular and again in ggplot, so install ggplot if you want to try it. | |
#install.packages("ggplot2") | |
library(ggplot2) | |
###Generate two random data sets### |
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
###Generate box coords | |
###A function to generat a blank box for use with geom_path() | |
box_coords <- function(x,y,size){ | |
b.x <- c(rep(x,2) - (size[1] / 2),rep(x,2) + (size[1] / 2)) | |
b.x[5] <- b.x[1] | |
b.y <- c(y-(size[2] / 2),rep(y,2)+(size[2] / 2),y-(size[2] / 2)) | |
b.y[5] <- b.y[1] | |
rmat <- data.frame(cbind(b.x,b.y)) | |
colnames(rmat) <- c("x","y") |
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
sm.q <- ddply(master.sm,.(noise,allee,cat),numcolwise(median),na.rm=T) | |
sm.names <- ddply(master.sm,.(allee,noise),numcolwise(median),na.rm=T) | |
sm.names <- sm.names[,1:2] | |
sm.names$aslope <- c(rep(-1.879652,5),rep(-1.584475,5)) | |
sm.q$ltype <- as.factor(rep(2,dim(sm.q)[1])) | |
sm.slope <- ggplot(master.sm, aes(x=meanslope,group=cat,fill=cat)) +geom_density(alpha=.5)+xlim(-3,0)+facet_grid(noise~allee,scale="free_y")+opts(axis.ticks = theme_blank(), axis.text.y = theme_blank())+scale_fill_manual("Catastrophe \n size",values=c("red","blue","black"))+xlab("Mean Slope")+ylab("Density") | |
sm.slope <- sm.slope+ geom_vline(aes(xintercept=-1),color="red", linetype="dashed", size=.3) | |
sm.slope <- sm.slope + geom_vline(data=sm.q,aes(xintercept=meanslope,color=cat,linetype="dashed"))+facet_grid(noise~allee,scales="free_y")+scale_colour_manual(values=c("red","blue","black"),legend= F) | |
sm.slope <- sm.slope + geom_vline(data=sm.names,aes(xintercept=aslope,legend=F,linetype="dashed",size=.8))+facet_grid(noise~allee,scales="free_y") |
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
###### The exponential growth of ecolog | |
###### Raw data can be found here | |
###### https://listserv.umd.edu/cgi-bin/wa?A2=ind1108e&L=ecolog-l&P=3401 | |
#####Data from Aug 31. 2011 post | |
require(date) | |
subscribers <- c(100,6000,7000,8000,9000,10000,11000,12000,13000) | |
start.date <- mdy.date(1,1,92) | |
month <- c("01/01/1992","09/01/2006","11/01/2007","10/01/2008","03/01/2009","04/01/2010","09/01/2010","02/01/2011","09/01/2011") | |
days <- as.date(month)-start.date |
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
#include libraries | |
require(twitteR) | |
require(ggplot2) | |
require(tm) | |
require(wordcloud) | |
require(RColorBrewer) | |
require(reshape) | |
# we can only access 1500 tweets without oauth | |
twit.data <- searchTwitter("#ESA2012",n=1500) |
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
# The data in the list you want to use lapply with | |
my_dat <- as.list(sample(1:10000,10, replace=T)) | |
foo_time <- function(dat,time_thresh = 2){ | |
start_time <- proc.time() | |
end_time <- 0 | |
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
gs.pal <- colorRampPalette(c("red","blue"),bias=.1,space="rgb") | |
x <- rnorm(100) | |
dat <- data.frame(cbind(x)) | |
dat$fac <- as.factor(sort(rep(1:5,20))) | |
dat$y <- x * as.numeric(dat$fac) | |
ggplot(dat,aes(x=x,y=y,colour=fac))+geom_point()+scale_colour_manual(values=gs.pal(5)) |
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
### Set-up theme | |
theme_popblk = function(size=12) { | |
o = list( | |
#axis.line=theme_blank(), | |
axis.text.x=theme_text(size=size*.9), | |
axis.text.y=theme_text(size=size*.9), | |
# axis.text.y=theme_blank(), | |
# axis.ticks.y=theme_blank(), | |
# axis.ticks=theme_blank(), | |
axis.ticks.length=unit(0.3, "lines"), |
OlderNewer