Lampe Speiser R file
require(ggplot2)
- library(directlabels)
library(RColorBrewer)
setwd("/Users/oakley/Dropbox/Road Work/euphPredation/") source(file="myFluc.R")
- Read Data
allTrials<-read.csv("EuphilomedesPredationTrials.csv") maleTrials<-subset(allTrials,allTrials$Sex=="male") chupaTable<-read.table("Chupa_Pred_Summary.csv",header=TRUE, sep = ",")
- FLUCTUATIONS PLOT MALES
source(file="myFluc.R") #customize style a little source(file="myFluc2.R") #divides by 2 for morini sample size
- chupacabra ggfluctuations plot
chupamatrix<-matrix(c(100, 112, 113, 20,8,7), byrow = FALSE, 3, 2) colnames(chupamatrix)<-c("Survivors","Lost") rownames(chupamatrix)<-c("Blindfolded","Control","Unaltered") chupaTable <- as.table(chupamatrix) p1<-myFluc(chupaTable)
- morini ggfluctuations plot
mormatrix<-matrix(c(8, 14, 45, 52, 46, 15), byrow = FALSE, 3, 2)
- scale morini divide by 2
colnames(mormatrix)<-c("Survivors","Lost") rownames(mormatrix)<-c("Blindfolded","Control","Unaltered") morTable <- as.table(mormatrix, ceiling=120) p2<-myFluc2(morTable)
- print both species next to each other
pushViewport(viewport(x = 0.25,y = 0.6, width = 0.5, height = 0.8,
angle = 0, name = "topleftvp"))
print(p1, vp = "topleftvp") pushViewport(viewport(x = 0.7,y = 0.6, width = 0.5, height = 0.8,
angle = 0, name = "botleftvp"))
print(p2, vp = "botleftvp")
- FLUCTUATIONS PLOT MALES M v F = FIGURE
source(file="myFluc.R") #customize style a little source(file="myFluc2.R") #divides by 2 for morini sample size
- Male versus Female morini ggfluctuations plot
MFmatrix<-matrix(c(58, 97, 157, 53), byrow = FALSE, 2, 2) colnames(MFmatrix)<-c("Survivors","Lost") rownames(MFmatrix)<-c("Male","Female") MFTable <- as.table(MFmatrix) MF <- myFluc(MFTable) MF
- SIMPLE BAR CHARTS
- Plot chupacabra results
chupaTrials<-subset(allTrials,allTrials$Species=="chupacabra") chupasums<-aggregate(chupaTrials$finish, by=list(Category=chupaTrials$Treatment), FUN=sum) chupatotal<-sum(chupaTrials$start/3)
c <- ggplot(chupasums, aes(x = reorder(Category, -x, mean), y = x)) + geom_bar(stat = 'identity') + xlab(expression(plain("Experimental Treatment"))) + ylab(expression(italic("E. chupacabra"))) + theme_bw(base_family="sans") chupabar <- c + geom_bar()
- plot morini results
moriniAllTrials<-subset(allTrials,allTrials$Species=="morini") moriniTrials<-subset(moriniAllTrials,moriniAllTrials$artifact=="no") moriniMaleTrials<-subset(moriniTrials, moriniTrials$Sex=="male") moriniFemaleTrials<-subset(moriniTrials, moriniTrials$Sex=="female") morinisums <- aggregate(moriniMaleTrials$finish, by=list(Category=moriniMaleTrials$Treatment), FUN=sum)
m <- ggplot(morinisums, aes(x = reorder(Category, -x, mean), y = x)) + geom_bar(stat = 'identity') + xlab(expression(plain("Experimental Treatment"))) + ylab(expression(italic("E. morini"))) + theme_bw(base_family="sans") morinibar <- m + geom_bar()
- print both species next to each other
pushViewport(viewport(x = 0.25,y = 0.6, width = 0.5, height = 0.8,
angle = 0, name = "topleftvp"))
print(chupabar, vp = "topleftvp") pushViewport(viewport(x = 0.7,y = 0.6, width = 0.5, height = 0.8,
angle = 0, name = "botleftvp"))
print(morinibar, vp = "botleftvp")
- Box Plot of porportions in each trial
par(mfrow=c(1,2)) boxplot(ratio~Treatment, data=chupaTrials,xlab=expression(plain("Experimental Treatment")),ylab=c("Proportion", "E. chupacabra Recovered"))
boxplot(ratio~Treatment, data=moriniMaleTrials,xlab=expression(plain("Experimental Treatment")),ylab=c("Proportion", "E. morini Recovered"))
- Bar charts with bar as stacks of trials -- Color
moriniStacks <- qplot(Treatment, data=moriniMaleTrials, geom="bar", weight=finish, fill=factor(Trial), ylab="E. morini recovered", xlab="", ymax=120) + theme_bw() + scale_fill_brewer(type="div", na.colour = "grey80") + labs(fill = "Trial") chupaStacks <- qplot(Treatment, data=chupaTrials, geom="bar", weight=finish, fill=factor(Trial), ylab="E. chupacabra recovered", xlab="", ymax=120) + theme_bw() + scale_fill_hue(h=c(20,275), l=50, c=70) + labs(fill = "Trial")
- print both species next to each other
pushViewport(viewport(x = 0.25,y = 0.6, width = 0.5, height = 0.8,
angle = 0, name = "topleftvp"))
print(chupaStacks, vp = "topleftvp") pushViewport(viewport(x = 0.7,y = 0.6, width = 0.5, height = 0.8,
angle = 0, name = "botleftvp"))
print(moriniStacks, vp = "botleftvp")
- Bar charts Male Predation with bar as stacks of trials -- BW
moriniStacks <- qplot(Treatment, data=moriniMaleTrials, geom="bar", weight=finish, fill=factor(Trial), ylab="E. morini (Male) Recovered", xlab="", ymax=120) + theme_bw() + scale_fill_grey() + labs(fill = "") +opts(legend.position="none") chupaStacks <- qplot(Treatment, data=chupaTrials, geom="bar", weight=finish, fill=factor(Trial), ylab="E. chupacabra (Male) Recovered", xlab="", ymax=120) + theme_bw() + scale_fill_grey() + labs(fill = "") +opts(legend.position="none")
- print both species next to each other
pushViewport(viewport(x = 0.25,y = 0.6, width = 0.5, height = 0.8,
angle = 0, name = "topleftvp"))
print(chupaStacks, vp = "topleftvp") pushViewport(viewport(x = 0.75,y = 0.6, width = 0.5, height = 0.8,
angle = 0, name = "botleftvp"))
print(moriniStacks, vp = "botleftvp")
- Bar charts Female Predation with bar as stacks of trials -- BW
moriniFStacks <- qplot(Treatment, data=moriniFemaleTrials, geom="bar", weight=finish, fill=factor(Trial), ylab="E. morini (Female) Recovered", xlab="", ymax=120) + theme_bw() + scale_fill_grey() + labs(fill = "") +opts(legend.position="none")
moriniFStacks
- Bar charts Female Predation with bar as stacks of trials -- Color
moriniFStacks <- qplot(Treatment, data=moriniFemaleTrials, geom="bar", weight=finish, fill=factor(Trial), ylab="E. morini (Female) Recovered", xlab="", ymax=120) + theme_bw() + scale_fill_brewer(type="qual", palette="Accent") + labs(fill = "") + opts(legend.position="none") moriniFStacks
- Figure5
- print both species next to each other
pushViewport(viewport(x = 0.2,y = 0.6, width = 0.3, height = 0.8,
angle = 0, name = "leftvp"))
print(chupaStacks, vp = "leftvp") pushViewport(viewport(x = 0.5,y = 0.6, width = 0.3, height = 0.8,
angle = 0, name = "midvp"))
print(moriniStacks, vp = "midvp") pushViewport(viewport(x = 0.8,y = 0.6, width = 0.3, height = 0.8,
angle = 0, name = "rightvp"))
print(moriniFStacks, vp = "rightvp")
- Figure for talk
- TESTING
- chupacabra ggfluctuations plot
chupamatrix<-matrix(c(100, 112, 113, 8,14,45,20,8,7,52,46,15), byrow = FALSE, 3, 4) colnames(chupamatrix)<-c("C Survivors","C Lost","M Survivors","M Lost") rownames(chupamatrix)<-c("Blindfolded","Control","Unaltered") chupaTable <- as.table(chupamatrix) myFluc(chupaTable)
ggplot(diamonds, aes(x=cut, y=price, group=cut))+
geom_boxplot(aes(fill=cut))+scale_fill_brewer(palette="OrRd")
- morini ggfluctuations plot
mormatrix<-matrix(c(8, 14, 45, 52, 46, 15), byrow = FALSE, 3, 2) colnames(mormatrix)<-c("Survivors","Lost") rownames(mormatrix)<-c("Blindfolded","Control","Unaltered") morTable <- as.table(mormatrix, ceiling=max(10)) p2<-myFluc(morTable)