Question 1:

Creating my functions
#############################
# FUNCTION: createHatchData()
# This function creates my hatch time dataset

createHatchData <- function(nGroup = 3, nName = c("Hot","Moderate", "Cool"), nSize = c(20,20,20), nMean = c(16,21,26),nSD = c(1.25,1.1,1.1), ID = 1:(sum(nSize))) {
  Hatch_time <- c(rnorm(n=nSize[1],mean=nMean[1],sd=nSD[1]),
                 rnorm(n=nSize[2],mean=nMean[2],sd=nSD[2]),
                 rnorm(n=nSize[3],mean=nMean[3],sd=nSD[3]))
Temperature <- rep(nName,nSize)
EggHatchData <- data.frame(ID,Temperature,Hatch_time)
return(EggHatchData)
}

###########################
# FUNCTION: EggHatchANOVA()
# This function performs an ANOVA on my EggHatchData using the createHatchData() function as its input

EggHatchANOVA <- function(x=createHatchData()){
  EggHatchAOV <- aov(Hatch_time~Temperature,data=x)
  print(summary(EggHatchAOV))
  z <- summary(EggHatchAOV)
  list(Fval=unlist(z)[7],probF=unlist(z)[9])
}

###########################
# FUNCTION: EggHatchPlot()
# This function plots a box and whisker plot using the createHatchData() function as its input

EggHatchPlot <- function(x=createHatchData()){
  ggplot(data=x,aes(x=Temperature,y=Hatch_time,fill=Temperature)) + geom_boxplot() + scale_fill_manual(values= c("blue","red","green"))
}
Running my functions
createHatchData()
##    ID Temperature Hatch_time
## 1   1         Hot   15.96897
## 2   2         Hot   15.34473
## 3   3         Hot   14.61324
## 4   4         Hot   16.72870
## 5   5         Hot   16.26772
## 6   6         Hot   17.47098
## 7   7         Hot   15.86554
## 8   8         Hot   16.82945
## 9   9         Hot   16.96111
## 10 10         Hot   15.31017
## 11 11         Hot   17.25140
## 12 12         Hot   14.99269
## 13 13         Hot   14.24289
## 14 14         Hot   15.01312
## 15 15         Hot   16.42939
## 16 16         Hot   15.67880
## 17 17         Hot   15.57885
## 18 18         Hot   16.70752
## 19 19         Hot   14.23622
## 20 20         Hot   15.42325
## 21 21    Moderate   21.92484
## 22 22    Moderate   21.27393
## 23 23    Moderate   23.88220
## 24 24    Moderate   20.52698
## 25 25    Moderate   21.65762
## 26 26    Moderate   20.02930
## 27 27    Moderate   20.76619
## 28 28    Moderate   20.03543
## 29 29    Moderate   22.10828
## 30 30    Moderate   21.29831
## 31 31    Moderate   21.37968
## 32 32    Moderate   19.51199
## 33 33    Moderate   21.67012
## 34 34    Moderate   21.35062
## 35 35    Moderate   21.81728
## 36 36    Moderate   19.49010
## 37 37    Moderate   21.65785
## 38 38    Moderate   18.84966
## 39 39    Moderate   19.92983
## 40 40    Moderate   23.86006
## 41 41        Cool   23.12029
## 42 42        Cool   25.96306
## 43 43        Cool   25.83880
## 44 44        Cool   26.38609
## 45 45        Cool   25.10427
## 46 46        Cool   25.36782
## 47 47        Cool   25.53106
## 48 48        Cool   23.85121
## 49 49        Cool   27.29890
## 50 50        Cool   26.78823
## 51 51        Cool   24.62284
## 52 52        Cool   24.81542
## 53 53        Cool   25.66946
## 54 54        Cool   26.11095
## 55 55        Cool   25.99804
## 56 56        Cool   27.67463
## 57 57        Cool   26.10524
## 58 58        Cool   27.07289
## 59 59        Cool   24.62522
## 60 60        Cool   27.65533
EggHatchANOVA()
##             Df Sum Sq Mean Sq F value Pr(>F)    
## Temperature  2 1006.6   503.3   340.8 <2e-16 ***
## Residuals   57   84.2     1.5                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## $Fval
## F value1 
## 340.7723 
## 
## $probF
##      Pr(>F)1 
## 1.966516e-32
EggHatchPlot()

Question 2:

Here I will modify my plotHatchData() function by changing the box and whisker plot to a violin plot as well as plotting an additional output graph: the density plot.

###########################
# FUNCTION: EggHatchPlot2()
# This function plots a box and whisker plot, jitter plot, and density plot using the createHatchData() function as its input

EggHatchPlot2 <- function(x=createHatchData()){
  boxplot <- ggplot(data=x,aes(x=Temperature,y=Hatch_time,fill=Temperature)) + geom_violin() + scale_fill_manual(values= c("blue","red","green"))
  
  density <- ggplot(data=x,aes(Hatch_time,fill=Temperature)) + geom_density() + scale_fill_manual(values= c(Cool="blue", Hot="red", Moderate = "green"))
  
  print(boxplot)
  print(density)
}
Running my functions using my newly modified EggHatchPlot2() function
createHatchData()
##    ID Temperature Hatch_time
## 1   1         Hot   13.55893
## 2   2         Hot   15.33028
## 3   3         Hot   14.63658
## 4   4         Hot   17.64185
## 5   5         Hot   16.10464
## 6   6         Hot   15.98806
## 7   7         Hot   14.72260
## 8   8         Hot   18.77055
## 9   9         Hot   13.55016
## 10 10         Hot   16.11683
## 11 11         Hot   17.76755
## 12 12         Hot   16.02248
## 13 13         Hot   16.13263
## 14 14         Hot   13.60503
## 15 15         Hot   15.70382
## 16 16         Hot   15.15475
## 17 17         Hot   13.83090
## 18 18         Hot   15.90686
## 19 19         Hot   16.26580
## 20 20         Hot   17.28209
## 21 21    Moderate   19.03143
## 22 22    Moderate   21.58344
## 23 23    Moderate   22.29472
## 24 24    Moderate   21.60672
## 25 25    Moderate   21.52211
## 26 26    Moderate   18.00211
## 27 27    Moderate   19.21371
## 28 28    Moderate   22.93399
## 29 29    Moderate   20.57832
## 30 30    Moderate   21.69841
## 31 31    Moderate   20.93746
## 32 32    Moderate   21.97534
## 33 33    Moderate   20.46767
## 34 34    Moderate   21.52228
## 35 35    Moderate   20.00567
## 36 36    Moderate   21.31748
## 37 37    Moderate   21.45597
## 38 38    Moderate   21.35689
## 39 39    Moderate   22.24218
## 40 40    Moderate   19.89730
## 41 41        Cool   23.86528
## 42 42        Cool   26.63696
## 43 43        Cool   28.17364
## 44 44        Cool   27.00934
## 45 45        Cool   26.32139
## 46 46        Cool   24.10413
## 47 47        Cool   25.62695
## 48 48        Cool   25.92994
## 49 49        Cool   24.81665
## 50 50        Cool   24.18172
## 51 51        Cool   25.39055
## 52 52        Cool   27.74101
## 53 53        Cool   25.50056
## 54 54        Cool   27.00860
## 55 55        Cool   25.07114
## 56 56        Cool   24.68472
## 57 57        Cool   25.96347
## 58 58        Cool   26.71588
## 59 59        Cool   25.67826
## 60 60        Cool   25.57882
EggHatchANOVA()
##             Df Sum Sq Mean Sq F value Pr(>F)    
## Temperature  2 1132.4   566.2   328.3 <2e-16 ***
## Residuals   57   98.3     1.7                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## $Fval
## F value1 
## 328.2646 
## 
## $probF
##     Pr(>F)1 
## 5.25049e-32
EggHatchPlot2()