######################################################
#
# Rats licking
#
######################################################

#### GRAEME'S ATTEMPT ####

######## histograms ########
alldata <- read.table(file.choose(), header = T, sep = ",") # load the data in 
head(alldata) # have a look at the column names
              # its clearly the column "licks" we want

lickdata <- alldata$licks
hist(lickdata)

hist(lickdata,xlim = c(0,70), ylim = c(0,200), xaxt="n", yaxt="n",xlab= "",ylab="",main=NULL)
abline(h=(seq(0,200,10)), col="lightgray")
abline(h=(seq(0,200,50)), col="darkgray")
par(new=TRUE)
hist(lickdata, col="dodgerblue3" ,xlim = c(0,70), ylim = c(0,200),
     ylab= "Frequency", xlab="Licks taken in 8 seconds", main=NULL)

######## boxplot ########
alldata <- read.table(file.choose(), header = T, sep = ",")
lickdata <- alldata$licks
par(mar = c(2,4,4,2))
boxplot(lickdata, ylab= "Number of licks in 8 seconds", ylim=c(-5,70), yaxs = "i", col="cadetblue1")

######## violin plot ########
install.packages("vioplot")
library(vioplot)

alldata <- read.table(file.choose(), header = T, sep = ",")
lickdata <- alldata$licks
par(mar = c(2,4,4,2))
vioplot(lickdata, ylab= "Number of licks in 8 seconds", ylim=c(-5,70), yaxs = "i", 
        xaxt = "n", col="cadetblue1")


#### ROSALIND'S ATTEMPT ####

rats <- read.table(file.choose(), header = T, sep = ",") # load in the data
View(rats) # view the data
licks<-rats$licks # give the data a convenient name

hist(licks) # look at the distribution of licks

hist(licks,xlim = c(0,70), ylim = c(0,200),xaxs="i",yaxs="i", 
     xaxt="n", yaxt="n",xlab= "",ylab="",main=NULL,col="white") # plot stripped-down histogram
abline(h=(seq(0,200,10)), col="lightgray") # add minor grid lines
abline(h=(seq(0,200,50)), col="darkgray") # add major grid lines

par(new=TRUE) # prepare to add to the existing plot
hist(licks, col="skyblue",xlim = c(0,70), ylim = c(0,200),xaxs="i",yaxs="i", 
     ylab= "Frequency", xlab="Number of licks", main=NULL) # plot neat histogram on top

summary(licks) # look at descriptive statistics

# Add some information (as lines, text, and arrows) to the figure:
abline(v=mean(licks),col="forestgreen",lty=2)
text(mean(licks)+1.5,150,labels="mean = 31.8",srt=90,col="forestgreen",font=2)
abline(v=median(licks),col="blue",lty=2)
text(median(licks)+1.5,150,labels="median = 41.0",srt=90,col="blue",font=2)
abline(v=6,col="red",lty=3)
abline(v=50,col="red",lty=3)
arrows(6,195,50,195,code=3,col="red",length=0.1)
text(28,185,labels="IQR = 44",font=2,col="red")


######################################################
#
# Fruitfly spermatophores
#
######################################################

#### GRAEME'S ATTEMPT ####

######## histograms ########
alldata <- read.table(file.choose(), header = T, sep = ",") # load the data in
head(alldata) # have a look at the column names
              # its clearly the column "spmass.mg" we want

massdata <- alldata$spmass.mg
hist(massdata)
summary(massdata)

hist(massdata,xlim = c(0,0.2), ylim = c(0,20), xaxt="n", yaxt="n",xlab= "",ylab="",main=NULL)
abline(h=(seq(0,20,1)), col="lightgray")
abline(h=(seq(0,20,5)), col="darkgray")
par(new=TRUE)
hist(massdata, col="coral1" ,xlim = c(0,0.2), ylim = c(0,20),
     ylab= "Frequency", xlab="Spermatophore mass (mg)", main=NULL)

######## violin plot ########
library(vioplot)
par(mar = c(2,4,4,2))
vioplot(massdata, ylab= "Spermatophore mass (mg)", ylim=c(0.03,0.18), yaxs = "i", 
        xaxt = "n", col="coral1")

######## boxplot ########
par(mar = c(2,4,4,2))
boxplot(massdata, ylab= "Spermatophore mass (mg)", ylim=c(0, 0.2), yaxs = "i", col="coral1")


#### ROSALIND'S ATTEMPT ####

firefly <- read.table(file.choose(), header = T, sep = ",") # load the data in
View(firefly) # view the data

mass <- firefly$spmass.mg  # give the data a convenient name

hist(mass) # look at the distribution of masses
summary(mass) # look at summary statistics

par(oma=c(0,1,0,0)) # create extra space to the left
boxplot(mass, ylab= "", yaxt="n",ylim=c(0, 0.2), yaxs = "i", 
        col="white") # plot stripped-down boxplot
abline(h=(seq(0,0.2,0.01)), col="lightgray") # add minor grid lines
abline(h=(seq(0,0.2,0.05)), col="darkgray") # add major grid lines
par(new=TRUE) # prepare to add to the existing plot
boxplot(mass, ylab= "", ylim=c(0, 0.2), yaxs = "i", 
        col="darkgoldenrod1",lwd=1,las=1) # plot neat boxplot on top
mtext("Spermatophore mass (mg)",side=2,line=4) # add y-axis label to the left of the boxplot
