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
################################ | |
# Problem: You have a ragged | |
# data frame where species that have not | |
# been seen as a site simply don't have a | |
# line in your data frame. You have a long | |
# data frame, but you want a long data frame | |
# where missing species have proper zeroes | |
# | |
# Solution: a combination of dcast and melt | |
# from the reshape2 package |
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
library(multifunc) | |
library(wesanderson) | |
data(all_biodepth) | |
allVars<-qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) | |
germany<-subset(all_biodepth, all_biodepth$location=="Germany") | |
vars<-whichVars(germany, allVars) | |
#re-normalize N.Soil so that everything is on the same sign-scale (e.g. the maximum level of a function is the "best" function) |
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
library(multifunc) | |
data(all_biodepth) | |
allVars<-qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) | |
germany<-subset(all_biodepth, all_biodepth$location=="Germany") | |
vars<-whichVars(germany, allVars) | |
#re-normalize N.Soil so that everything is on the same sign-scale (e.g. the maximum level of a function is the "best" function) | |
germany$N.Soil<- -1*germany$N.Soil +max(germany$N.Soil, na.rm=TRUE) |
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
\documentclass{article} | |
\begin{document} | |
<<echo=FALSE>>= | |
activityDF <- structure(list(julian_day = 1:365, food = c(92.6182247978374, | |
199.361820535986, 128.619308542186, 131.048504694701, 44.6344539529983, | |
139.02542881751, 118.815437972886, 85.5963235153311, 73.9459098960665, | |
85.6671795660157, 195.954639346317, 192.942941724749, 193.341526021202, | |
142.419581610027, 130.23002915561, 232.843857188757, 105.14817987285, | |
131.58751463704, 123.30056211349, 150.447279408636, 138.40775613945, |
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
#just create a range of values | |
grdVals <- function(x, bound=0.01) seq(range(x)[1]-bound, range(x)[2]+bound, length.out=50) | |
#instantiate a new persp object for a scatterplot | |
makeScatterBox <- function(x,y,z, bound=0, ...){ | |
x <- grdVals(x, bound=bound) | |
y <- grdVals(y, bound=bound) | |
z <- grdVals(z, bound=bound) | |
z <- matrix(rep(z, 50), nrow=50) |
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
#devtools::install_github("rstudio/leaflet", ref="feature/color-legend") | |
library(leaflet) | |
library(RColorBrewer) | |
set.seed(100) | |
pdf <- data.frame(Latitude = runif(100, -90,90), Longitude = runif(100, -180,180)) | |
#make a property with colors | |
pdf$Study <- rep(1:10,10) | |
#need to create a pal using colorbin |
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 9.
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
"ID","Title","Name","Project.Link","Goal" | |
1,"Why is this Dolphin's Fin on Backwards!?","Matthew S. Leslie","http://www.rockethub.com/projects/3754-why-is-this-dolphin-s-fin-on-backwards","5000" | |
2,"Tracking the migration of the Atlantic Puffin","Robin Freeman","http://www.rockethub.com/projects/3818-tracking-the-migration-of-the-atlantic-puffin","5000" | |
3,"Cancer? Yeast has the answers","Marisa Alonso-N??ez","http://www.rockethub.com/projects/3753-cancer-yeast-has-the-answers","2500" | |
4,"Athlete's Foot in Worms?","Rebecca Rashid Achterman","http://www.rockethub.com/projects/3703-athlete-s-foot-in-worms","1000" | |
5,"Support Zombie Research!","Kelly Weinersmith","http://www.rockethub.com/projects/3737-support-zombie-research","3500" | |
6,"Doctor Zen and the Amazon Crayfish","Zen Faulkes","http://www.rockethub.com/projects/3695-doctor-zen-and-the-amazon-crayfish","1000" | |
7,"C-Cilia in Motion!!","Aditya Rao","http://www.rockethub.com/projects/3792-c-cilia-in-motion","5000" | |
8,"Force of Duck: Measuring explosive erection"," |
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
###############FUNCTIONS | |
#If you find the 0 predators remaining formulation more intuitive | |
pEaten2<-function(Sp.max, E, prey.vec) { | |
1-mean(dhyper(0,prey.vec, Sp.max-prey.vec, Sp.max-E)) | |
} | |
#vectorize it | |
pEaten2<-Vectorize(pEaten2, vectorize.args="E") | |
#generate all permutations of prey being eaten |
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
require(plyr); require(stringr); require(ggplot2); require(lubridate); require(twitteR) | |
##need to figure out why there are two datout objects and not just 1... | |
twitterPlot<-function(myString, n=1500, since=NULL, until=NULL){ | |
since2<-as.character(strptime(since, '%Y-%m-%d')+2*24*60*60) | |
until2<-as.character(strptime(until, '%Y-%m-%d')+2*24*60*60) | |
datout_1 <- searchTwitter(myString, n = n, since=since, until=until) | |
datout_2 <- searchTwitter(myString, n = n, since=since2, until=until2) |
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("./sciFundFunctions.r") | |
library(gridExtra) | |
################################################# | |
#######HISTOGRAMS | |
################################################# | |
#total raised histogram distribution | |
raised<-qplot(total, data=projects) + | |
theme_bw(base_size=16) + | |
xlab("\nTotal Raised") + |
OlderNewer