#Behavior #Import Data setwd("~/Documents/R files Octopus") behaviornew <- read.csv("~/Documents/R files Octopus/behaviornew.csv") ##Set factors behaviornew$maleorder=factor(behaviornew$maleorder) behaviornew$variable=factor(behaviornew$variable) #Grouped Bar Plot maleorder <- table(behavior$mating, behavior$fighting, behavior$resting, behavior$maleorder) test <- read.csv("~/Documents/R files Octopus/test.csv") test$maleorder=factor(test$maleorder) # check the dataset head(behaviornew) # plot it ggplot(data=behaviornew, aes(x=maleorder, y=times, fill=variable), geom_bar(stat="identity", position=position_dodge(), colour="black") ) library(ggplot2) behaviornew <- read.table(text="maleorder variable times 1 mating 2567 1 fighting 2495 1 resting 2434 2 mating 1871 2 fighting 2592 2 resting 3322 1 mating 2709 1 fighting 347 1 resting 4634 2 mating 1370 2 fighting 331 2 resting 5643 1 mating 8970 1 fighting 136 1 resting 1537 2 mating 7476 2 fighting 488 2 resting 2423 1 mating 2034 1 fighting 110 1 resting 5610 2 mating 2642 2 fighting 0 2 resting 5544 3 mating 8682 3 fighting 0 3 resting 353 2 mating 3491 2 fighting 121 2 resting 3523 3 mating 1153 3 fighting 180 3 resting 3178 1 mating 8155 1 fighting 473 1 resting 564 2 mating 4555 2 fighting 349 2 resting 2645 3 mating 5136 3 fighting 695 3 resting 1409 1 mating 2751 1 fighting 1152 1 resting 3271 1 mating 8682 1 fighting 0 1 resting 1081 2 mating 6554 2 fighting 0 2 resting 1389 1 mating 4940 1 fighting 64 1 resting 1983 1 mating 8531 1 fighting 866 1 resting 268 2 mating 3356 2 fighting 368 2 resting 1161 3 mating 485 3 fighting 862 3 resting 2989 1 mating 3180 1 fighting 56 1 resting 3797 2 mating 8106 2 fighting 99 2 resting 321 3 mating 1522 3 fighting 0 3 resting 5247 2 mating 4118 2 fighting 99 2 resting 3047 1 mating 1952 1 fighting 7 1 resting 2868 2 mating 3508 2 fighting 27 2 resting 3765 3 mating 4215 3 fighting 18 3 resting 2482 1 mating 7366 1 fighting 31 1 resting 154 2 mating 8778 2 fighting 0 2 resting 30 3 mating 1921 3 fighting 0 3 resting 4314 1 mating 4162 1 fighting 0 1 resting 2819 2 mating 8993 2 fighting 0 2 resting 2584 3 mating 2780 3 fighting 0 3 resting 4177 3 mating 3613 3 fighting 10 3 resting 4008 1 mating 1849 1 fighting 163 1 resting 5837 2 mating 102 2 fighting 38 2 mating 7216 3 fighting 1578 3 resting 402 3 mating 5339 1 fighting 3265 1 mating 0 1 fighting 3918 2 resting 3977 2 mating 0 2 fighting 3568 3 mating 6883 3 fighting 0 3 resting 2495 1 mating 3477 1 fighting 0 1 mating 3969 2 fighting 2703 2 resting 0 2 mating 3318 3 fighting 1437 3 mating 0 3 fighting 6154 1 resting 3057 1 mating 4 1 fighting 3876 2 mating 1308 2 resting 10 2 fighting 5688", header=T) ggplot(behaviornew, aes(factor(maleorder), times, fill = variable)) + geom_bar(stat="identity", position = "dodge") + scale_fill_brewer(palette = "Set1") behaviormean <- read.table(text="maleorder variable meantime sterror 1 mating 4567.470588 640.3217718 1 fighting 347.2941176 156.4921245 1 resting 2860 425.2185078 2 mating 4288.705882 665.4902923 2 fighting 266 150.4534567 2 resting 3246.294118 475.2001882 3 mating 3283.75 730.3483304 3 fighting 180.5833333 88.29928947 3 resting 3512.083333 488.8292051", header=T) #change background theme_set(theme_bw(24)) ggplot(behaviormean, aes(x=maleorder, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9)) + xlab("Male Order") + ylab("Mean Time in Seconds") + ggtitle("Mean Time Spent on Each Behavior vs. Male Mating Order") + theme(plot.title = element_text(size=20, vjust=1, lineheight=0.6), axis.title.x = element_text(size=16, vjust = -0.3), axis.title.y = element_text(size=16, vjust=1), axis.text.x = element_text(size=12), axis.text.y=element_text(size=12)) behaviormeannew <- read.table(text="maleorder variable meantime sterror 1 mating 3531 842 2 mating 4119 781 3 mating 3911 710 1 fighting 157 61 2 fighting 266 41 3 fighting 113 78 1 resting 3640 585 2 resting 3394 547 3 resting 4000 524", header=T) ggplot(behaviormeannew, aes(x=maleorder, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9)) + xlab("Male Order") + ylab("Mean Time in Seconds") + ggtitle("Mean Time Spent on Each Behavior vs. Male Mating Order") + theme(plot.title = element_text(size=20, vjust=1, lineheight=0.6), axis.title.x = element_text(size=16, vjust = -0.3), axis.title.y = element_text(size=16, vjust=1), axis.text.x = element_text(size=12), axis.text.y=element_text(size=12)) #Male beahavior mating order behaviormeannew1 <- read.table(text="maleorder variable meantime sterror 1 mating 3739 842 2 mating 3443 844 3 mating 2780 709 1 fighting 320 179 2 fighting 104 43 3 fighting 143 67 1 resting 3283 566 2 resting 4159 547 3 resting 4072 557", header=T) ggplot(behaviormeannew1, aes(x=maleorder, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9)) + xlab("Male Mate Order") + ylab("Mean Time in Seconds") + ggtitle("Mean Time Spent on Each Behavior vs. Male Mating Order") + theme(plot.title = element_text(size=20, vjust=1, lineheight=0.6), axis.title.x = element_text(size=16, vjust = -0.3), axis.title.y = element_text(size=16, vjust=1), axis.text.x = element_text(size=12), axis.text.y=element_text(size=12)) #Male size relative to female behaviormeannew2 <- read.table(text="malesize variable meantime sterror s mating 3632 569 s fighting 295 41 s resting 3269 397 m mating 3028 707 m fighting 161 52 m resting 3980 632 l mating 2805 657 l fighting 216 107 l resting 4388 445", header=T) behaviormeannew2$malesize=factor(behaviormeannew2$malesize, c("s","m","l")) behaviormeannew2$variable=factor(behaviormeannew2$variable) ggplot(behaviormeannew2, aes(x=malesize, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9)) + xlab("Male Size Relative to Female") + ylab("Mean Time in Seconds") + ggtitle("Mean Time Spent on Each Behavior vs. Male Mating Order") + theme(plot.title = element_text(size=20, vjust=1, lineheight=0.6), axis.title.x = element_text(size=16, vjust = -0.3), axis.title.y = element_text(size=16, vjust=1), axis.text.x = element_text(size=12), axis.text.y=element_text(size=12)) behaviormeannew3 <- read.table(text="malesize variable meantime sterror s mating 3797.59 569.86 s fighting 308.73 125.68 s resting 3114.09 381.21 m mating 3634.00 699.69 m fighting 175.50 61.47 m resting 3426.50 616.49 l mating 3503.65 743.71 l fighting 258.95 132.20 l resting 3723.35 438.35", header=T) behaviormeannew3$malesize=factor(behaviormeannew3$malesize, c("s","m","l")) behaviormeannew3$variable=factor(behaviormeannew3$variable) ggplot(behaviormeannew3, aes(x=malesize, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9)) + xlab("Male Size Relative to Other Males") + ylab("Mean Time in Seconds") + ggtitle("Mean Time Spent on Each Behavior vs. Male Size Relative to Other Males") + theme(plot.title = element_text(size=20, vjust=1, lineheight=0.6), axis.title.x = element_text(size=16, vjust = -0.3), axis.title.y = element_text(size=16, vjust=1), axis.text.x = element_text(size=12), axis.text.y=element_text(size=12)) #Female size relative to females behaviormeannew4 <- read.table(text="femalesize variable meantime sterror s mating 1818 521 s fighting 321 155 s resting 4778 429 m mating 3268 853 m fighting 208 80 m resting 3647 610 l mating 4344 549 l fighting 173 62 l resting 3187 388", header=T) behaviormeannew4$femalesize=factor(behaviormeannew4$femalesize, c("s","m","l")) behaviormeannew4$variable=factor(behaviormeannew4$variable) ggplot(behaviormeannew4, aes(x=femalesize, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9)) + xlab("Female Size Relative to Other Females") + ylab("Mean Time in Seconds") + ggtitle("Mean Time Spent on Each Behavior vs. Female Size Relative to Other Females") + theme(plot.title = element_text(size=20, vjust=1, lineheight=0.6), axis.title.x = element_text(size=16, vjust = -0.3), axis.title.y = element_text(size=16, vjust=1), axis.text.x = element_text(size=12), axis.text.y=element_text(size=12)) #Black Background ggplot(behaviormeannew4, aes(x=femalesize, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9), color="white") + xlab("Female Size Relative to Other Females") + ylab("Mean Time in Seconds") + theme(panel.background = element_rect(fill = 'black'), plot.background = element_rect(fill="black"), plot.title = element_text(size=20, vjust=1, lineheight=0.6), axis.title.x = element_text(size=20, vjust = -0.3, color="white"), axis.title.y = element_text(size=20, vjust=1, color="white"), axis.text.x = element_text(size=20, color="white"), axis.text.y=element_text(size=20, color="white")) ggplot(behaviormeannew3, aes(x=malesize, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9), color="white") + xlab("Male Size Relative to Other Males") + ylab("Mean Time in Seconds") + theme(panel.background = element_rect(fill = 'black'), plot.background = element_rect(fill="black"), plot.title = element_text(size=20, vjust=1, lineheight=0.6, color="white"), axis.title.x = element_text(size=20, vjust = -0.3, color="white"), axis.title.y = element_text(size=20, vjust=1, color="white"), axis.text.x = element_text(size=30, color="white"), axis.text.y=element_text(size=20, color="white")) ggplot(behaviormeannew2, aes(x=malesize, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9), color="white") + xlab("Male Size Relative to Female") + ylab("Mean Time in Seconds") + theme(panel.background = element_rect(fill = 'black'), plot.background = element_rect(fill="black"), plot.title = element_text(size=20, vjust=1, lineheight=0.6, color="white"), axis.title.x = element_text(size=20, vjust = -0.3, color="white"), axis.title.y = element_text(size=20, vjust=1, color="white"), axis.text.x = element_text(size=30, color="white"), axis.text.y=element_text(size=20, color="white")) ggplot(behaviormean, aes(x=maleorder, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9), color="white") + xlab("Male Order") + ylab("Mean Time in Seconds") + theme(panel.background = element_rect(fill = 'black'), plot.background = element_rect(fill="black"), plot.title = element_text(size=20, vjust=1, lineheight=0.6, color="white"), axis.title.x = element_text(size=20, vjust = -0.3, color="white"), axis.title.y = element_text(size=20, vjust=1, color="white"), axis.text.x = element_text(size=30, color="white"), axis.text.y=element_text(size=20, color="white")) ggplot(behaviormeannew, aes(x=maleorder, y=meantime, fill=variable)) + geom_bar(position=position_dodge(), stat="identity") + scale_fill_manual(values=c("#9EBCDA","#8C6BB1","#810F7C"), guide = guide_legend(title = "Behavior"), labels = c("Fighting", "Mating", "Resting")) + geom_errorbar(aes(ymin=meantime-sterror, ymax=meantime+sterror), width=.2, # Width of the error bars position=position_dodge(.9), color="white") + xlab("Male Order") + ylab("Mean Time in Seconds") + theme(panel.background = element_rect(fill = 'black'), plot.background = element_rect(fill="black"), plot.title = element_text(size=20, vjust=1, lineheight=0.6, color="white"), axis.title.x = element_text(size=20, vjust = -0.3, color="white"), axis.title.y = element_text(size=20, vjust=1, color="white"), axis.text.x = element_text(size=30, color="white"), axis.text.y=element_text(size=20, color="white"))