finalsurvival <- read.csv("C:/Users/User/Desktop/PHD/R/csvfiles/Observations/finalsurvival.csv") finalsurvival <- read.csv("finalsurvival.csv") #Sofia added this line head(finalsurvival) ###some basic statistics first### ##prop of herb and no herb that survived#### whole<-filter(finalsurvival,initial_condition=="Whole") wholedead<-filter(whole,final_condition==1) 24/40 herb<-filter(finalsurvival,initial_condition=="Herbivorised") herbdead<-filter(herb,final_condition==1) 37/40 survival.glm<-glm(final_condition~initial_condition,data=finalsurvival ,family=binomial) summary(survival.glm) #Sofia's addition #Could also use Pearson's chi squared test countdata <- matrix(c(16,24,3,37),nrow=2) countdata #column 1 x row 1 = intact seedlings alive #column 1 x row 2 = intact seedlings dead #column 2 x row 1 = herbivorised seedlings alive #column 2 x row 2 = herbivorised seedlings dead chisq.test(countdata) #NB! Since one of the entries in the contingency table small (<5), Fisher's exact test better fisher.test(countdata) ##plot require(ggplot2) png("C:/Users/mert3408/Desktop/PHD/R/Rscripts/barplot.png", units='in',width = 6, height = 6, res = 400, bg="transparent") p <- ggplot(data=finalsurvival, aes(x=initial_condition,fill=factor(final_condition), stat="identity"))+ geom_bar(position="stack")+ xlab("Initial Condition") + ylab("Count")+ scale_fill_discrete(name='Final Condition', labels = c("Alive","Dead")) p <- p + theme( panel.background = element_rect(fill = "transparent", colour = NA), panel.grid.minor = element_blank(), panel.grid.major = element_blank(), plot.background = element_rect(fill = "transparent", colour = NA)) p dev.off()