Wednesday, November 5, 2014

11 5 2014 Degree Days to Peak Brood with Graph

Updated Degree Day graph to show degree days after peak spawn of last group.
tempandspawning.R
require(plyr)
## Loading required package: plyr
require(doBy)
## Loading required package: doBy
## Loading required package: survival
## Loading required package: splines
## Loading required package: MASS
require(ggplot2)
## Loading required package: ggplot2
reproanalysis<-read.csv('ReproAnalysis.csv', header=T)
print(reproanalysis)
##       X       Date       Site Temp Pop Brooders Gaping Percent Dead Closed
## 1     1 2014-05-02    Fidalgo 10.0   N        0      0   0.000   NA     NA
## 2     2 2014-05-16    Fidalgo  9.0   N        0     53   0.000    0     46
## 3     3 2014-05-24    Fidalgo 10.0   N        0     24   0.000    0     86
## 4     4 2014-05-30    Fidalgo 10.0   N        0     46   0.000    0     50
## 5     5 2014-06-06    Fidalgo 10.0   N        1     59   1.695    2     36
## 6     6 2014-06-13    Fidalgo  7.0   N        0     68   0.000    1     27
## 7     7 2014-06-20    Fidalgo  8.0   N        0     76   0.000    0     34
## 8     8 2014-06-27    Fidalgo  9.0   N        1     87   1.149    0      6
## 9     9 2014-07-04    Fidalgo  9.0   N        1     82   1.220    0     13
## 10   10 2014-07-11    Fidalgo 16.0   N        0     78   0.000    0     17
## 11   11 2014-07-18    Fidalgo 10.0   N        0     68   0.000    0     40
## 12   12 2014-07-25    Fidalgo 11.0   N        0     55   0.000    0     45
## 13   13 2014-08-01    Fidalgo 10.0   N        0     28   0.000    0     68
## 14   14 2014-08-08    Fidalgo 11.0   N        5     89   5.618    0     10
## 15   15 2014-04-30 Manchester  9.5   N        0      0   0.000   NA     NA
## 16   16 2014-05-14 Manchester  9.0   N        0     31   0.000    0     28
## 17   17 2014-05-21 Manchester 10.0   N        0     40   0.000    3     48
## 18   18 2014-05-28 Manchester 13.0   N        0     54   0.000   15     28
## 19   19 2014-06-04 Manchester  8.0   N        0     43   0.000   15     32
## 20   20 2014-06-11 Manchester  9.0   N        0     41   0.000    8     12
## 21   21 2014-06-18 Manchester  7.0   N        0     73   0.000    2     12
## 22   22 2014-06-25 Manchester 10.0   N        1     53   1.887   23     19
## 23   23 2014-07-02 Manchester 10.0   N        0     40   0.000   20     18
## 24   24 2014-07-09 Manchester 11.0   N        0     45   0.000   12      2
## 25   25 2014-07-16 Manchester 10.0   N        0     61   0.000    6      8
## 26   26 2014-07-23 Manchester  8.0   N        0     60   0.000   10      9
## 27   27 2014-07-30 Manchester 11.0   N        0     45   0.000   12      7
## 28   28 2014-08-06 Manchester 18.0   N        0     45   0.000    4      5
## 29   29 2014-05-01 Oyster Bay 11.0   N        0     NA   0.000   NA     NA
## 30   30 2014-05-15 Oyster Bay 13.0   N        0     46   0.000    7     14
## 31   31 2014-05-22 Oyster Bay 13.0   N        0      3   0.000   93      5
## 32   32 2014-05-29 Oyster Bay 15.0   N        2     51   3.922    6     10
## 33   33 2014-06-05 Oyster Bay 13.0   N        1     52   1.923    7      8
## 34   34 2014-06-12 Oyster Bay 15.0   N        2     48   4.167    8      1
## 35   35 2014-06-19 Oyster Bay 16.0   N        3     54   5.556    8      1
## 36   36 2014-06-26 Oyster Bay 14.0   N        7    156   4.487   26      2
## 37   37 2014-07-03 Oyster Bay 15.0   N        0     49   0.000    0      1
## 38   38 2014-07-10 Oyster Bay 16.0   N        8     73  10.959    3      2
## 39   39 2014-07-17 Oyster Bay 16.0   N        0     48   0.000    1      1
## 40   40 2014-07-24 Oyster Bay 15.0   N        3     68   4.412    0     10
## 41   41 2014-07-31 Oyster Bay 17.0   N        1     50   2.000    0      0
## 42   42 2014-08-07 Oyster Bay 15.0   N        3     71   4.225    0      7
## 43   43 2014-05-02    Fidalgo 10.0   H        0     NA   0.000   NA     NA
## 44   44 2014-05-16    Fidalgo  9.0   H        0     48   0.000    0     52
## 45   45 2014-05-24    Fidalgo 10.0   H        0     53   0.000    0     30
## 46   46 2014-05-30    Fidalgo 10.0   H        0     50   0.000    1     40
## 47   47 2014-06-06    Fidalgo 10.0   H        0     58   0.000    0     33
## 48   48 2014-06-13    Fidalgo  7.0   H        0     72   0.000    0     27
## 49   49 2014-06-20    Fidalgo  8.0   H        0     77   0.000    0     10
## 50   50 2014-06-27    Fidalgo  9.0   H        0     65   0.000    0     28
## 51   51 2014-07-04    Fidalgo  9.0   H        1     88   1.136    0      9
## 52   52 2014-07-11    Fidalgo 16.0   H        0     70   0.000    0     28
## 53   53 2014-07-18    Fidalgo 10.0   H        2     32   6.250    0     50
## 54   54 2014-07-25    Fidalgo 11.0   H        2     50   4.000    0     36
## 55   55 2014-08-01    Fidalgo 10.0   H        0     84   0.000    0      2
## 56   56 2014-08-08    Fidalgo 11.0   H        3     67   4.478    0     15
## 57   57 2014-04-30 Manchester  9.5   H        0     NA   0.000   NA     NA
## 58   58 2014-05-14 Manchester  9.0   H        0     25   0.000    0     72
## 59   59 2014-05-21 Manchester 10.0   H        0     16   0.000    2     66
## 60   60 2014-05-28 Manchester 13.0   H        0     27   0.000    0     58
## 61   61 2014-06-04 Manchester  8.0   H        0     55   0.000   11     23
## 62   62 2014-06-11 Manchester  9.0   H        0     63   0.000    2     31
## 63   63 2014-06-18 Manchester  7.0   H        0     63   0.000    4     12
## 64   64 2014-06-25 Manchester 10.0   H        1     52   1.923    7     33
## 65   65 2014-07-02 Manchester 10.0   H        0     52   0.000   20      8
## 66   66 2014-07-09 Manchester 11.0   H        1     60   1.667    5     21
## 67   67 2014-07-16 Manchester 10.0   H        1     56   1.786    8     17
## 68   68 2014-07-23 Manchester  8.0   H        1     67   1.493    7      9
## 69   69 2014-07-30 Manchester 11.0   H        1     45   2.222    9     11
## 70   70 2014-08-06 Manchester 18.0   H        2     77   2.597   12      5
## 71   71 2014-05-01 Oyster Bay 11.0   H        0     NA   0.000   NA     NA
## 72   72 2014-05-15 Oyster Bay 13.0   H        0     49   0.000    7     33
## 73   73 2014-05-22 Oyster Bay 13.0   H        0     47   0.000   51      9
## 74   74 2014-05-29 Oyster Bay 15.0   H        1     80   1.250    7      2
## 75   75 2014-06-05 Oyster Bay 13.0   H        2     79   2.532    7      3
## 76   76 2014-06-12 Oyster Bay 15.0   H        1     86   1.163    8      1
## 77   77 2014-06-19 Oyster Bay 16.0   H        0     70   0.000    9      7
## 78   78 2014-06-26 Oyster Bay 14.0   H        1     92   1.087    4      1
## 79   79 2014-07-03 Oyster Bay 15.0   H        3     66   4.545    4      4
## 80   80 2014-07-10 Oyster Bay 16.0   H        6     83   7.229    3      3
## 81   81 2014-07-17 Oyster Bay 16.0   H        5     68   7.353    6      1
## 82   82 2014-07-24 Oyster Bay 15.0   H        4     72   5.556    4      6
## 83   83 2014-07-31 Oyster Bay 17.0   H        1     59   1.695    2      8
## 84   84 2014-08-07 Oyster Bay 15.0   H        2     80   2.500    0      6
## 85   85 2014-05-02    Fidalgo 10.0   S        0     NA   0.000   NA     NA
## 86   86 2014-05-16    Fidalgo  9.0   S        0     55   0.000    0     NA
## 87   87 2014-05-24    Fidalgo 10.0   S        0     77   0.000    0     NA
## 88   88 2014-05-30    Fidalgo 10.0   S        0     77   0.000    1     55
## 89   89 2014-06-06    Fidalgo 10.0   S        0     53   0.000    1     26
## 90   90 2014-06-13    Fidalgo  7.0   S        7     83   8.434    1     39
## 91   91 2014-06-20    Fidalgo  8.0   S        1     83   1.205    0      8
## 92   92 2014-06-27    Fidalgo  9.0   S        3     87   3.448    0      4
## 93   93 2014-07-04    Fidalgo  9.0   S        6     71   8.451    0     21
## 94   94 2014-07-11    Fidalgo 16.0   S       11     81  13.580    0     11
## 95   95 2014-07-18    Fidalgo 10.0   S        0     67   0.000    0     26
## 96   96 2014-07-25    Fidalgo 11.0   S        6     72   8.333    0     32
## 97   97 2014-08-01    Fidalgo 10.0   S        3     45   6.667    0     49
## 98   98 2014-08-08    Fidalgo 11.0   S        2     70   2.857    0     23
## 99   99 2014-04-30 Manchester  9.5   S        0     NA   0.000   NA     43
## 100 100 2014-05-14 Manchester  9.0   S        0     43   0.000    0     37
## 101 101 2014-05-21 Manchester 10.0   S        0     76   0.000    3      6
## 102 102 2014-05-28 Manchester 13.0   S        0     43   0.000    9      3
## 103 103 2014-06-04 Manchester  8.0   S        0     60   0.000    3     28
## 104 104 2014-06-11 Manchester  9.0   S        0     49   0.000   12      1
## 105 105 2014-06-18 Manchester  7.0   S        1     55   1.818   10     10
## 106 106 2014-06-25 Manchester 10.0   S        0     50   0.000    2     13
## 107 107 2014-07-02 Manchester 10.0   S        0     31   0.000    4      2
## 108 108 2014-07-09 Manchester 11.0   S        0     55   0.000   22      6
## 109 109 2014-07-16 Manchester 10.0   S        3     59   5.085   12     48
## 110 110 2014-07-23 Manchester  8.0   S        2     59   3.390    1      3
## 111 111 2014-07-30 Manchester 11.0   S        1     69   1.449   10     14
## 112 112 2014-08-06 Manchester 18.0   S        4     50   8.000   11     15
## 113 113 2014-05-01 Oyster Bay 11.0   S        0     NA   0.000   NA      1
## 114 114 2014-05-15 Oyster Bay 13.0   S        0     59   0.000    8     11
## 115 115 2014-05-22 Oyster Bay 13.0   S        0      2   0.000   68     12
## 116 116 2014-05-29 Oyster Bay 15.0   S        5     74   6.757    9      2
## 117 117 2014-06-05 Oyster Bay 13.0   S        2     60   3.333   12     30
## 118 118 2014-06-12 Oyster Bay 15.0   S        3     63   4.762   11      6
## 119 119 2014-06-19 Oyster Bay 16.0   S       11     80  13.750   12      7
## 120 120 2014-06-26 Oyster Bay 14.0   S       11     85  12.941   10     25
## 121 121 2014-07-03 Oyster Bay 15.0   S        9     78  11.538    0     10
## 122 122 2014-07-10 Oyster Bay 16.0   S       10     82  12.195    0      2
## 123 123 2014-07-17 Oyster Bay 16.0   S        0     75   0.000    1     38
## 124 124 2014-07-24 Oyster Bay 15.0   S        8     75  10.667    4      7
## 125 125 2014-07-31 Oyster Bay 17.0   S        0     70   0.000    0      1
## 126 126 2014-08-07 Oyster Bay 15.0   S       10     80  12.500    0     22
##      Total  Tide arcsinbrooders    prop arcsinprop
## 1   100.00 -0.84          0.000      NA     0.0000
## 2    99.00 -2.27          0.000 0.00000     0.0000
## 3   110.00  1.12          0.000 0.00000     0.0000
## 4    96.00 -1.46          0.000 0.00000     0.0000
## 5    98.69  3.13          1.571 0.01695     0.1306
## 6    96.00 -2.81          0.000 0.00000     0.0000
## 7   110.00  2.14          0.000 0.00000     0.0000
## 8    94.15 -1.42          1.571 0.01149     0.1074
## 9    96.22  2.58          1.571 0.01220     0.1107
## 10   95.00 -2.57          0.000 0.00000     0.0000
## 11  108.00  2.05          0.000 0.00000     0.0000
## 12  100.00 -0.78          0.000 0.00000     0.0000
## 13   96.00  2.39          0.000 0.00000     0.0000
## 14  104.62 -1.66          0.000 0.05618     0.2393
## 15   90.00 -1.50          0.000      NA     0.0000
## 16   59.00 -1.63          0.000 0.00000     0.0000
## 17   91.00  0.87          0.000 0.00000     0.0000
## 18   97.00 -1.83          0.000 0.00000     0.0000
## 19   90.00  1.70          0.000 0.00000     0.0000
## 20   61.00 -1.75          0.000 0.00000     0.0000
## 21   87.00  0.19          0.000 0.00000     0.0000
## 22   96.89 -1.49          1.571 0.01887     0.1378
## 23   78.00  0.94          0.000 0.00000     0.0000
## 24   59.00 -1.12          0.000 0.00000     0.0000
## 25   75.00 -0.28          0.000 0.00000     0.0000
## 26   79.00 -0.60          0.000 0.00000     0.0000
## 27   64.00  0.86          0.000 0.00000     0.0000
## 28   54.00 -0.14          0.000 0.00000     0.0000
## 29  100.00 -1.53          0.000      NA     0.0000
## 30   67.00 -2.43          0.000 0.00000     0.0000
## 31  101.00  2.31          0.000 0.00000     0.0000
## 32   67.00 -2.00          0.000 0.03922     0.1993
## 33   67.00  2.97          1.571 0.01923     0.1391
## 34   61.17 -2.47          0.000 0.04167     0.2056
## 35   68.56  1.93          0.000 0.05556     0.2379
## 36  182.00 -1.72          0.000 0.04487     0.2134
## 37   50.00  2.14          0.000 0.00000     0.0000
## 38   88.96 -2.19          0.000 0.10959     0.3374
## 39   50.00  1.42          0.000 0.00000     0.0000
## 40   82.41 -0.85          0.000 0.04412     0.2116
## 41   52.00  1.84          1.571 0.02000     0.1419
## 42   82.23 -1.05          0.000 0.04225     0.2070
## 43   94.00 -0.84          0.000      NA     0.0000
## 44  100.00 -2.27          0.000 0.00000     0.0000
## 45   83.00  1.12          0.000 0.00000     0.0000
## 46   91.00 -1.46          0.000 0.00000     0.0000
## 47   91.00  3.13          0.000 0.00000     0.0000
## 48   99.00 -2.81          0.000 0.00000     0.0000
## 49   87.00  2.14          0.000 0.00000     0.0000
## 50   93.00 -1.42          0.000 0.00000     0.0000
## 51   98.14  2.58          1.571 0.01136     0.1068
## 52   98.00 -2.57          0.000 0.00000     0.0000
## 53   88.25  2.05          0.000 0.06250     0.2527
## 54   90.00 -0.78          0.000 0.04000     0.2014
## 55   86.00  2.39          0.000 0.00000     0.0000
## 56   86.48 -1.66          0.000 0.04478     0.2132
## 57   89.00 -1.50          0.000      NA     0.0000
## 58   97.00 -1.63          0.000 0.00000     0.0000
## 59   84.00  0.87          0.000 0.00000     0.0000
## 60   85.00 -1.83          0.000 0.00000     0.0000
## 61   89.00  1.70          0.000 0.00000     0.0000
## 62   96.00 -1.75          0.000 0.00000     0.0000
## 63   79.00  0.19          0.000 0.00000     0.0000
## 64   93.92 -1.49          1.571 0.01923     0.1391
## 65   80.00  0.94          0.000 0.00000     0.0000
## 66   87.67 -1.12          1.571 0.01667     0.1295
## 67   82.79 -0.28          1.571 0.01786     0.1340
## 68   84.49 -0.60          1.571 0.01493     0.1225
## 69   67.22  0.86          1.571 0.02222     0.1496
## 70   96.60 -0.14          0.000 0.02597     0.1619
## 71  101.00 -1.53          0.000      NA     0.0000
## 72   89.00 -2.43          0.000 0.00000     0.0000
## 73  107.00  2.31          0.000 0.00000     0.0000
## 74   89.00 -2.00          1.571 0.01250     0.1120
## 75   89.00  2.97          0.000 0.02532     0.1598
## 76   96.16 -2.47          1.571 0.01163     0.1080
## 77   86.00  1.93          0.000 0.00000     0.0000
## 78   98.09 -1.72          1.571 0.01087     0.1044
## 79   78.55  2.14          0.000 0.04545     0.2148
## 80   96.23 -2.19          0.000 0.07229     0.2722
## 81   82.35  1.42          0.000 0.07353     0.2746
## 82   87.56 -0.85          0.000 0.05556     0.2379
## 83   70.69  1.84          1.571 0.01695     0.1306
## 84   88.50 -1.05          0.000 0.02500     0.1588
## 85   94.00 -0.84          0.000      NA     0.0000
## 86   74.00 -2.27          0.000 0.00000     0.0000
## 87   93.00  1.12          0.000 0.00000     0.0000
## 88  133.00 -1.46          0.000 0.00000     0.0000
## 89   80.00  3.13          0.000 0.00000     0.0000
## 90  131.43 -2.81          0.000 0.08434     0.2947
## 91   91.00  2.14          1.571 0.01205     0.1100
## 92   94.45 -1.42          0.000 0.03448     0.1868
## 93   92.00  2.58          0.000 0.08451     0.2950
## 94   92.00 -2.57          0.000 0.13580     0.3774
## 95   93.00  2.05          0.000 0.00000     0.0000
## 96  104.00 -0.78          0.000 0.08333     0.2928
## 97   94.00  2.39          0.000 0.06667     0.2612
## 98   93.00 -1.66          0.000 0.02857     0.1698
## 99   43.00 -1.50          0.000      NA     0.0000
## 100  80.00 -1.63          0.000 0.00000     0.0000
## 101  85.00  0.87          0.000 0.00000     0.0000
## 102  55.00 -1.83          0.000 0.00000     0.0000
## 103  91.00  1.70          0.000 0.00000     0.0000
## 104  62.00 -1.75          0.000 0.00000     0.0000
## 105  76.82  0.19          1.571 0.01818     0.1353
## 106  65.00 -1.49          0.000 0.00000     0.0000
## 107  37.00  0.94          0.000 0.00000     0.0000
## 108  83.00 -1.12          0.000 0.00000     0.0000
## 109 124.08 -0.28          0.000 0.05085     0.2274
## 110  66.39 -0.60          0.000 0.03390     0.1852
## 111  94.45  0.86          1.571 0.01449     0.1207
## 112  84.00 -0.14          0.000 0.08000     0.2868
## 113   1.00 -1.53          0.000      NA     0.0000
## 114  78.00 -2.43          0.000 0.00000     0.0000
## 115  82.00  2.31          0.000 0.00000     0.0000
## 116  91.76 -2.00          0.000 0.06757     0.2630
## 117 105.33  2.97          0.000 0.03333     0.1836
## 118  84.76 -2.47          0.000 0.04762     0.2200
## 119 112.75  1.93          0.000 0.13750     0.3799
## 120 132.94 -1.72          0.000 0.12941     0.3680
## 121  99.54  2.14          0.000 0.11538     0.3466
## 122  96.20 -2.19          0.000 0.12195     0.3567
## 123 114.00  1.42          0.000 0.00000     0.0000
## 124  96.67 -0.85          0.000 0.10667     0.3327
## 125  71.00  1.84          0.000 0.00000     0.0000
## 126 114.50 -1.05          0.000 0.12500     0.3614
#First we will find the time in days between the threshold temp and the peak brooding
peakbrood<-ddply(reproanalysis,.(Site,Pop),subset,Brooders==max(Brooders, na.rm=T))
print(peakbrood)
##      X       Date       Site Temp Pop Brooders Gaping Percent Dead Closed
## 1   56 2014-08-08    Fidalgo   11   H        3     67   4.478    0     15
## 2   14 2014-08-08    Fidalgo   11   N        5     89   5.618    0     10
## 3   94 2014-07-11    Fidalgo   16   S       11     81  13.580    0     11
## 4   70 2014-08-06 Manchester   18   H        2     77   2.597   12      5
## 5   22 2014-06-25 Manchester   10   N        1     53   1.887   23     19
## 6  112 2014-08-06 Manchester   18   S        4     50   8.000   11     15
## 7   80 2014-07-10 Oyster Bay   16   H        6     83   7.229    3      3
## 8   38 2014-07-10 Oyster Bay   16   N        8     73  10.959    3      2
## 9  119 2014-06-19 Oyster Bay   16   S       11     80  13.750   12      7
## 10 120 2014-06-26 Oyster Bay   14   S       11     85  12.941   10     25
##     Total  Tide arcsinbrooders    prop arcsinprop
## 1   86.48 -1.66          0.000 0.04478     0.2132
## 2  104.62 -1.66          0.000 0.05618     0.2393
## 3   92.00 -2.57          0.000 0.13580     0.3774
## 4   96.60 -0.14          0.000 0.02597     0.1619
## 5   96.89 -1.49          1.571 0.01887     0.1378
## 6   84.00 -0.14          0.000 0.08000     0.2868
## 7   96.23 -2.19          0.000 0.07229     0.2722
## 8   88.96 -2.19          0.000 0.10959     0.3374
## 9  112.75  1.93          0.000 0.13750     0.3799
## 10 132.94 -1.72          0.000 0.12941     0.3680
#find the dates with maximum number of brooders
oysthresh<-ddply(oysmintemp,.(Date),subset,min_temp>=12.5)
#create a list of temps to find those above threshold temp for minimum daily temps at each site
print(oysthresh)
##           Date min_temp
## 1   2013-08-18    17.38
## 2   2013-08-19    17.38
## 3   2013-08-20    17.66
## 4   2013-08-21    17.76
## 5   2013-08-22    17.66
## 6   2013-08-23    17.76
## 7   2013-08-24    17.57
## 8   2013-08-25    17.48
## 9   2013-08-26    17.38
## 10  2013-08-27    17.09
## 11  2013-08-28    17.09
## 12  2013-08-29    17.00
## 13  2013-08-30    16.90
## 14  2013-08-31    17.09
## 15  2013-09-01    17.19
## 16  2013-09-02    17.19
## 17  2013-09-03    17.28
## 18  2013-09-04    17.48
## 19  2013-09-05    17.57
## 20  2013-09-06    17.38
## 21  2013-09-07    17.28
## 22  2013-09-08    17.48
## 23  2013-09-09    17.48
## 24  2013-09-10    17.28
## 25  2013-09-11    17.19
## 26  2013-09-12    17.09
## 27  2013-09-13    17.19
## 28  2013-09-14    17.09
## 29  2013-09-15    17.19
## 30  2013-09-16    17.00
## 31  2013-09-17    17.00
## 32  2013-09-18    16.81
## 33  2013-09-19    16.90
## 34  2013-09-20    16.71
## 35  2013-09-21    16.71
## 36  2013-09-22    16.33
## 37  2013-09-23    16.14
## 38  2013-09-24    15.66
## 39  2013-09-25    15.47
## 40  2013-09-26    15.38
## 41  2013-09-27    15.28
## 42  2013-09-28    15.19
## 43  2013-09-29    14.80
## 44  2013-09-30    14.42
## 45  2013-10-01    13.94
## 46  2013-10-02    14.13
## 47  2013-10-03    13.94
## 48  2013-10-04    13.94
## 49  2013-10-05    14.13
## 50  2013-10-06    13.94
## 51  2013-10-07    14.04
## 52  2013-10-10    12.59
## 53  2013-10-11    13.46
## 54  2013-10-12    13.46
## 55  2013-10-13    12.88
## 56  2013-10-14    13.17
## 57  2013-10-15    12.98
## 58  2013-10-16    13.08
## 59  2013-10-17    13.17
## 60  2013-10-18    12.79
## 61  2013-10-19    12.59
## 62  2013-10-23    12.59
## 63  2014-05-14    12.69
## 64  2014-05-15    12.59
## 65  2014-05-16    12.69
## 66  2014-05-17    13.08
## 67  2014-05-18    13.27
## 68  2014-05-19    13.17
## 69  2014-05-20    13.27
## 70  2014-05-21    13.27
## 71  2014-05-22    13.46
## 72  2014-05-23    13.17
## 73  2014-05-24    13.56
## 74  2014-05-25    13.46
## 75  2014-05-26    13.56
## 76  2014-05-27    13.56
## 77  2014-05-28    13.46
## 78  2014-05-29    13.65
## 79  2014-05-30    13.65
## 80  2014-05-31    13.85
## 81  2014-06-01    13.75
## 82  2014-06-02    14.04
## 83  2014-06-03    14.04
## 84  2014-06-04    14.04
## 85  2014-06-05    14.23
## 86  2014-06-06    13.94
## 87  2014-06-07    14.13
## 88  2014-06-08    14.04
## 89  2014-06-09    13.94
## 90  2014-06-10    14.61
## 91  2014-06-11    13.94
## 92  2014-06-12    14.61
## 93  2014-06-13    14.90
## 94  2014-06-14    14.80
## 95  2014-06-15    14.71
## 96  2014-06-16    14.42
## 97  2014-06-17    14.42
## 98  2014-06-18    14.42
## 99  2014-06-19    14.52
## 100 2014-06-20    14.52
## 101 2014-06-21    15.00
## 102 2014-06-22    14.90
## 103 2014-06-23    14.80
## 104 2014-06-24    14.80
## 105 2014-06-25    15.28
## 106 2014-06-26    15.38
## 107 2014-06-27    15.47
## 108 2014-06-28    15.66
## 109 2014-06-29    15.57
## 110 2014-06-30    15.57
## 111 2014-07-01    15.66
## 112 2014-07-02    15.57
## 113 2014-07-03    15.86
## 114 2014-07-04    16.14
## 115 2014-07-05    15.76
## 116 2014-07-06    15.66
## 117 2014-07-07    16.24
## 118 2014-07-08    16.24
## 119 2014-07-09    16.24
## 120 2014-07-10    16.52
## 121 2014-07-11    17.19
## 122 2014-07-12    17.19
## 123 2014-07-13    17.28
## 124 2014-07-14    17.48
## 125 2014-07-15    17.19
## 126 2014-07-16    17.66
## 127 2014-07-17    17.48
## 128 2014-07-18    17.48
## 129 2014-07-19    17.19
## 130 2014-07-20    17.19
## 131 2014-07-21    17.28
## 132 2014-07-22    17.09
## 133 2014-07-23    17.00
## 134 2014-07-24    17.00
## 135 2014-07-25    16.90
## 136 2014-07-26    17.00
## 137 2014-07-27    17.09
## 138 2014-07-28    17.19
## 139 2014-07-29    17.38
## 140 2014-07-30    17.57
## 141 2014-07-31    17.76
## 142 2014-08-01    17.86
## 143 2014-08-02    17.76
## 144 2014-08-03    17.86
## 145 2014-08-04    17.48
## 146 2014-08-05    17.57
## 147 2014-08-06    17.76
## 148 2014-08-07    17.76
## 149 2014-08-08    17.95
## 150 2014-08-09    18.05
## 151 2014-08-10    18.24
## 152 2014-08-11    18.43
## 153 2014-08-12    18.05
## 154 2014-08-13    18.05
## 155 2014-08-14    18.05
## 156 2014-08-15    17.95
## 157 2014-08-16    17.86
## 158 2014-08-17    17.76
## 159 2014-08-18    17.66
## 160 2014-08-19    17.38
## 161 2014-08-20    17.86
## 162 2014-08-21    17.66
## 163 2014-08-22    17.76
## 164 2014-08-23    17.76
## 165 2014-08-24    17.66
## 166 2014-08-25    17.76
## 167 2014-08-26    17.76
## 168 2014-08-27    17.76
## 169 2014-08-28    17.86
## 170 2014-08-29    18.05
## 171 2014-08-30    17.76
## 172 2014-08-31    17.48
## 173 2014-09-01    17.48
## 174 2014-09-02    17.28
## 175 2014-09-03    17.19
## 176 2014-09-04    17.09
## 177 2014-09-05    17.38
## 178 2014-09-06    17.28
## 179 2014-09-07    17.38
## 180 2014-09-08    17.28
## 181 2014-09-09    17.28
## 182 2014-09-10    17.19
## 183 2014-09-11    17.09
## 184 2014-09-12    16.90
## 185 2014-09-13    16.81
## 186 2014-09-14    16.62
## 187 2014-09-15    16.62
## 188 2014-09-16    16.62
## 189 2014-09-17    16.71
## 190 2014-09-18    16.52
## 191 2014-09-19    16.62
fidthresh<-ddply(fidmintemp,.(Date),subset,min_temp>=12.5)
View(fidthresh)
manthresh<-ddply(manmintemp,.(Date),subset,min_temp>=12.5)
View(manthresh)
peakbrood$Date<-as.Date(peakbrood$Date)
oysthresh$Date<-as.Date(oysthresh$Date)
fidthresh$Date<-as.Date(fidthresh$Date)
manthresh$Date<-as.Date(manthresh$Date)
#make sure everything works as a Date in R after producing all the threshold temp data
d<-c("2014-06-03","2014-06-08","2014-05-14")
#dates visually confirmed for threshold temps
p<-c("Fidalgo","Manchester","Oyster Bay")
thresholddate<-data.frame(p,d)
thresholddate$d<-as.Date(thresholddate$d)
peakthresh<-merge(peakbrood,thresholddate,by.x="Site",by.y="p",all=F)
print(peakthresh)
##          Site   X       Date Temp Pop Brooders Gaping Percent Dead Closed
## 1     Fidalgo  56 2014-08-08   11   H        3     67   4.478    0     15
## 2     Fidalgo  14 2014-08-08   11   N        5     89   5.618    0     10
## 3     Fidalgo  94 2014-07-11   16   S       11     81  13.580    0     11
## 4  Manchester  70 2014-08-06   18   H        2     77   2.597   12      5
## 5  Manchester  22 2014-06-25   10   N        1     53   1.887   23     19
## 6  Manchester 112 2014-08-06   18   S        4     50   8.000   11     15
## 7  Oyster Bay  80 2014-07-10   16   H        6     83   7.229    3      3
## 8  Oyster Bay  38 2014-07-10   16   N        8     73  10.959    3      2
## 9  Oyster Bay 119 2014-06-19   16   S       11     80  13.750   12      7
## 10 Oyster Bay 120 2014-06-26   14   S       11     85  12.941   10     25
##     Total  Tide arcsinbrooders    prop arcsinprop          d
## 1   86.48 -1.66          0.000 0.04478     0.2132 2014-06-03
## 2  104.62 -1.66          0.000 0.05618     0.2393 2014-06-03
## 3   92.00 -2.57          0.000 0.13580     0.3774 2014-06-03
## 4   96.60 -0.14          0.000 0.02597     0.1619 2014-06-08
## 5   96.89 -1.49          1.571 0.01887     0.1378 2014-06-08
## 6   84.00 -0.14          0.000 0.08000     0.2868 2014-06-08
## 7   96.23 -2.19          0.000 0.07229     0.2722 2014-05-14
## 8   88.96 -2.19          0.000 0.10959     0.3374 2014-05-14
## 9  112.75  1.93          0.000 0.13750     0.3799 2014-05-14
## 10 132.94 -1.72          0.000 0.12941     0.3680 2014-05-14
#create a data frame that compares dates for threshold and peak spawning dates
peakthresh$time_to_peak<-difftime(peakthresh$Date,peakthresh$d,units="days")
#finds the difference in days between threshold temp and peak spawning
print(peakthresh)
##          Site   X       Date Temp Pop Brooders Gaping Percent Dead Closed
## 1     Fidalgo  56 2014-08-08   11   H        3     67   4.478    0     15
## 2     Fidalgo  14 2014-08-08   11   N        5     89   5.618    0     10
## 3     Fidalgo  94 2014-07-11   16   S       11     81  13.580    0     11
## 4  Manchester  70 2014-08-06   18   H        2     77   2.597   12      5
## 5  Manchester  22 2014-06-25   10   N        1     53   1.887   23     19
## 6  Manchester 112 2014-08-06   18   S        4     50   8.000   11     15
## 7  Oyster Bay  80 2014-07-10   16   H        6     83   7.229    3      3
## 8  Oyster Bay  38 2014-07-10   16   N        8     73  10.959    3      2
## 9  Oyster Bay 119 2014-06-19   16   S       11     80  13.750   12      7
## 10 Oyster Bay 120 2014-06-26   14   S       11     85  12.941   10     25
##     Total  Tide arcsinbrooders    prop arcsinprop          d time_to_peak
## 1   86.48 -1.66          0.000 0.04478     0.2132 2014-06-03      66 days
## 2  104.62 -1.66          0.000 0.05618     0.2393 2014-06-03      66 days
## 3   92.00 -2.57          0.000 0.13580     0.3774 2014-06-03      38 days
## 4   96.60 -0.14          0.000 0.02597     0.1619 2014-06-08      59 days
## 5   96.89 -1.49          1.571 0.01887     0.1378 2014-06-08      17 days
## 6   84.00 -0.14          0.000 0.08000     0.2868 2014-06-08      59 days
## 7   96.23 -2.19          0.000 0.07229     0.2722 2014-05-14      57 days
## 8   88.96 -2.19          0.000 0.10959     0.3374 2014-05-14      57 days
## 9  112.75  1.93          0.000 0.13750     0.3799 2014-05-14      36 days
## 10 132.94 -1.72          0.000 0.12941     0.3680 2014-05-14      43 days
peakthresh2<-peakthresh[c("Date","Site","Pop","Brooders","d","time_to_peak")]
#subsets df to only relevant information
peakthresh2<-rename(peakthresh2,c('Date'='Peak_Date',"Site"="Site","Pop"="Pop","Brooders"="Brooders","d"="Threshold Date","time_to_peak"="Days_to_Peak"))
#renames df columns to more meaningful names
print(peakthresh2)
##     Peak_Date       Site Pop Brooders Threshold Date Days_to_Peak
## 1  2014-08-08    Fidalgo   H        3     2014-06-03      66 days
## 2  2014-08-08    Fidalgo   N        5     2014-06-03      66 days
## 3  2014-07-11    Fidalgo   S       11     2014-06-03      38 days
## 4  2014-08-06 Manchester   H        2     2014-06-08      59 days
## 5  2014-06-25 Manchester   N        1     2014-06-08      17 days
## 6  2014-08-06 Manchester   S        4     2014-06-08      59 days
## 7  2014-07-10 Oyster Bay   H        6     2014-05-14      57 days
## 8  2014-07-10 Oyster Bay   N        8     2014-05-14      57 days
## 9  2014-06-19 Oyster Bay   S       11     2014-05-14      36 days
## 10 2014-06-26 Oyster Bay   S       11     2014-05-14      43 days
#next we want to find the degree days from minimum winter temp to spawning peak
#looking at previously generated temp graphs we decided that 8 was minimum winter temp
#we have to visually confirm when the temps continually increase from 8 to spawning
oysdd<-ddply(oysmintemp,.(Date),subset,min_temp>=8)
#subsets minimum temp data to find dates with temps above 8 C.
oysdd<-oysmintemp[c(oysmintemp$Date>="2014-03-06"),]
#after visually confirming the initial temp date we then subset the data from this point on
print(oysdd)
##           Date min_temp
## 201 2014-03-06    8.082
## 202 2014-03-07    8.282
## 203 2014-03-08    8.382
## 204 2014-03-09    8.382
## 205 2014-03-10    8.382
## 206 2014-03-11    8.879
## 207 2014-03-12    8.779
## 208 2014-03-13    8.779
## 209 2014-03-14    8.680
## 210 2014-03-15    8.779
## 211 2014-03-16    8.879
## 212 2014-03-17    8.779
## 213 2014-03-18    8.779
## 214 2014-03-19    8.879
## 215 2014-03-20    8.680
## 216 2014-03-21    8.779
## 217 2014-03-22    8.879
## 218 2014-03-23    8.879
## 219 2014-03-24    8.978
## 220 2014-03-25    8.978
## 221 2014-03-26    9.176
## 222 2014-03-27    9.176
## 223 2014-03-28    9.275
## 224 2014-03-29    9.275
## 225 2014-03-30    9.176
## 226 2014-03-31    9.275
## 227 2014-04-01    9.275
## 228 2014-04-02    9.373
## 229 2014-04-03    9.571
## 230 2014-04-04    9.571
## 231 2014-04-05    9.669
## 232 2014-04-06    9.571
## 233 2014-04-07    9.669
## 234 2014-04-08    9.669
## 235 2014-04-09    9.866
## 236 2014-04-10    9.866
## 237 2014-04-11   10.063
## 238 2014-04-12   10.161
## 239 2014-04-13   10.455
## 240 2014-04-14   10.553
## 241 2014-04-15   10.748
## 242 2014-04-16   10.944
## 243 2014-04-17   10.748
## 244 2014-04-18   10.651
## 245 2014-04-19   10.651
## 246 2014-04-20   10.651
## 247 2014-04-21   10.553
## 248 2014-04-22   10.553
## 249 2014-04-23   10.651
## 250 2014-04-24   10.651
## 251 2014-04-25   10.846
## 252 2014-04-26   10.748
## 253 2014-04-27   10.748
## 254 2014-04-28   10.846
## 255 2014-04-29   10.944
## 256 2014-04-30   11.139
## 257 2014-05-01   11.236
## 258 2014-05-02   11.431
## 259 2014-05-03   12.013
## 260 2014-05-04   11.819
## 261 2014-05-05   11.722
## 262 2014-05-06   11.722
## 263 2014-05-07   11.625
## 264 2014-05-08   11.625
## 265 2014-05-09   11.625
## 266 2014-05-10   11.819
## 267 2014-05-11   11.916
## 268 2014-05-12   12.013
## 269 2014-05-13   12.013
## 270 2014-05-14   12.690
## 271 2014-05-15   12.594
## 272 2014-05-16   12.690
## 273 2014-05-17   13.076
## 274 2014-05-18   13.269
## 275 2014-05-19   13.173
## 276 2014-05-20   13.269
## 277 2014-05-21   13.269
## 278 2014-05-22   13.461
## 279 2014-05-23   13.173
## 280 2014-05-24   13.558
## 281 2014-05-25   13.461
## 282 2014-05-26   13.558
## 283 2014-05-27   13.558
## 284 2014-05-28   13.461
## 285 2014-05-29   13.654
## 286 2014-05-30   13.654
## 287 2014-05-31   13.846
## 288 2014-06-01   13.750
## 289 2014-06-02   14.038
## 290 2014-06-03   14.038
## 291 2014-06-04   14.038
## 292 2014-06-05   14.230
## 293 2014-06-06   13.942
## 294 2014-06-07   14.134
## 295 2014-06-08   14.038
## 296 2014-06-09   13.942
## 297 2014-06-10   14.613
## 298 2014-06-11   13.942
## 299 2014-06-12   14.613
## 300 2014-06-13   14.900
## 301 2014-06-14   14.804
## 302 2014-06-15   14.709
## 303 2014-06-16   14.421
## 304 2014-06-17   14.421
## 305 2014-06-18   14.421
## 306 2014-06-19   14.517
## 307 2014-06-20   14.517
## 308 2014-06-21   14.996
## 309 2014-06-22   14.900
## 310 2014-06-23   14.804
## 311 2014-06-24   14.804
## 312 2014-06-25   15.282
## 313 2014-06-26   15.378
## 314 2014-06-27   15.473
## 315 2014-06-28   15.664
## 316 2014-06-29   15.569
## 317 2014-06-30   15.569
## 318 2014-07-01   15.664
## 319 2014-07-02   15.569
## 320 2014-07-03   15.855
## 321 2014-07-04   16.141
## 322 2014-07-05   15.760
## 323 2014-07-06   15.664
## 324 2014-07-07   16.237
## 325 2014-07-08   16.237
## 326 2014-07-09   16.237
## 327 2014-07-10   16.523
## 328 2014-07-11   17.189
## 329 2014-07-12   17.189
## 330 2014-07-13   17.284
## 331 2014-07-14   17.475
## 332 2014-07-15   17.189
## 333 2014-07-16   17.665
## 334 2014-07-17   17.475
## 335 2014-07-18   17.475
## 336 2014-07-19   17.189
## 337 2014-07-20   17.189
## 338 2014-07-21   17.284
## 339 2014-07-22   17.094
## 340 2014-07-23   16.999
## 341 2014-07-24   16.999
## 342 2014-07-25   16.903
## 343 2014-07-26   16.999
## 344 2014-07-27   17.094
## 345 2014-07-28   17.189
## 346 2014-07-29   17.379
## 347 2014-07-30   17.570
## 348 2014-07-31   17.760
## 349 2014-08-01   17.855
## 350 2014-08-02   17.760
## 351 2014-08-03   17.855
## 352 2014-08-04   17.475
## 353 2014-08-05   17.570
## 354 2014-08-06   17.760
## 355 2014-08-07   17.760
## 356 2014-08-08   17.950
## 357 2014-08-09   18.045
## 358 2014-08-10   18.236
## 359 2014-08-11   18.426
## 360 2014-08-12   18.045
## 361 2014-08-13   18.045
## 362 2014-08-14   18.045
## 363 2014-08-15   17.950
## 364 2014-08-16   17.855
## 365 2014-08-17   17.760
## 366 2014-08-18   17.665
## 367 2014-08-19   17.379
## 368 2014-08-20   17.855
## 369 2014-08-21   17.665
## 370 2014-08-22   17.760
## 371 2014-08-23   17.760
## 372 2014-08-24   17.665
## 373 2014-08-25   17.760
## 374 2014-08-26   17.760
## 375 2014-08-27   17.760
## 376 2014-08-28   17.855
## 377 2014-08-29   18.045
## 378 2014-08-30   17.760
## 379 2014-08-31   17.475
## 380 2014-09-01   17.475
## 381 2014-09-02   17.284
## 382 2014-09-03   17.189
## 383 2014-09-04   17.094
## 384 2014-09-05   17.379
## 385 2014-09-06   17.284
## 386 2014-09-07   17.379
## 387 2014-09-08   17.284
## 388 2014-09-09   17.284
## 389 2014-09-10   17.189
## 390 2014-09-11   17.094
## 391 2014-09-12   16.903
## 392 2014-09-13   16.808
## 393 2014-09-14   16.618
## 394 2014-09-15   16.618
## 395 2014-09-16   16.618
## 396 2014-09-17   16.713
## 397 2014-09-18   16.523
## 398 2014-09-19   16.618
#we have to subset temp data to just the time frame between 8C beginning and peak spawn for each pop at each site
#luckily two pops at each site had the same spawn time data so we use that
oyshndd<-oysdd[c(oysdd$Date<="2014-07-10"),]
oyssdd<-oysdd[c(oysdd$Date<="2014-06-19"),]
print(oyshndd)
##           Date min_temp
## 201 2014-03-06    8.082
## 202 2014-03-07    8.282
## 203 2014-03-08    8.382
## 204 2014-03-09    8.382
## 205 2014-03-10    8.382
## 206 2014-03-11    8.879
## 207 2014-03-12    8.779
## 208 2014-03-13    8.779
## 209 2014-03-14    8.680
## 210 2014-03-15    8.779
## 211 2014-03-16    8.879
## 212 2014-03-17    8.779
## 213 2014-03-18    8.779
## 214 2014-03-19    8.879
## 215 2014-03-20    8.680
## 216 2014-03-21    8.779
## 217 2014-03-22    8.879
## 218 2014-03-23    8.879
## 219 2014-03-24    8.978
## 220 2014-03-25    8.978
## 221 2014-03-26    9.176
## 222 2014-03-27    9.176
## 223 2014-03-28    9.275
## 224 2014-03-29    9.275
## 225 2014-03-30    9.176
## 226 2014-03-31    9.275
## 227 2014-04-01    9.275
## 228 2014-04-02    9.373
## 229 2014-04-03    9.571
## 230 2014-04-04    9.571
## 231 2014-04-05    9.669
## 232 2014-04-06    9.571
## 233 2014-04-07    9.669
## 234 2014-04-08    9.669
## 235 2014-04-09    9.866
## 236 2014-04-10    9.866
## 237 2014-04-11   10.063
## 238 2014-04-12   10.161
## 239 2014-04-13   10.455
## 240 2014-04-14   10.553
## 241 2014-04-15   10.748
## 242 2014-04-16   10.944
## 243 2014-04-17   10.748
## 244 2014-04-18   10.651
## 245 2014-04-19   10.651
## 246 2014-04-20   10.651
## 247 2014-04-21   10.553
## 248 2014-04-22   10.553
## 249 2014-04-23   10.651
## 250 2014-04-24   10.651
## 251 2014-04-25   10.846
## 252 2014-04-26   10.748
## 253 2014-04-27   10.748
## 254 2014-04-28   10.846
## 255 2014-04-29   10.944
## 256 2014-04-30   11.139
## 257 2014-05-01   11.236
## 258 2014-05-02   11.431
## 259 2014-05-03   12.013
## 260 2014-05-04   11.819
## 261 2014-05-05   11.722
## 262 2014-05-06   11.722
## 263 2014-05-07   11.625
## 264 2014-05-08   11.625
## 265 2014-05-09   11.625
## 266 2014-05-10   11.819
## 267 2014-05-11   11.916
## 268 2014-05-12   12.013
## 269 2014-05-13   12.013
## 270 2014-05-14   12.690
## 271 2014-05-15   12.594
## 272 2014-05-16   12.690
## 273 2014-05-17   13.076
## 274 2014-05-18   13.269
## 275 2014-05-19   13.173
## 276 2014-05-20   13.269
## 277 2014-05-21   13.269
## 278 2014-05-22   13.461
## 279 2014-05-23   13.173
## 280 2014-05-24   13.558
## 281 2014-05-25   13.461
## 282 2014-05-26   13.558
## 283 2014-05-27   13.558
## 284 2014-05-28   13.461
## 285 2014-05-29   13.654
## 286 2014-05-30   13.654
## 287 2014-05-31   13.846
## 288 2014-06-01   13.750
## 289 2014-06-02   14.038
## 290 2014-06-03   14.038
## 291 2014-06-04   14.038
## 292 2014-06-05   14.230
## 293 2014-06-06   13.942
## 294 2014-06-07   14.134
## 295 2014-06-08   14.038
## 296 2014-06-09   13.942
## 297 2014-06-10   14.613
## 298 2014-06-11   13.942
## 299 2014-06-12   14.613
## 300 2014-06-13   14.900
## 301 2014-06-14   14.804
## 302 2014-06-15   14.709
## 303 2014-06-16   14.421
## 304 2014-06-17   14.421
## 305 2014-06-18   14.421
## 306 2014-06-19   14.517
## 307 2014-06-20   14.517
## 308 2014-06-21   14.996
## 309 2014-06-22   14.900
## 310 2014-06-23   14.804
## 311 2014-06-24   14.804
## 312 2014-06-25   15.282
## 313 2014-06-26   15.378
## 314 2014-06-27   15.473
## 315 2014-06-28   15.664
## 316 2014-06-29   15.569
## 317 2014-06-30   15.569
## 318 2014-07-01   15.664
## 319 2014-07-02   15.569
## 320 2014-07-03   15.855
## 321 2014-07-04   16.141
## 322 2014-07-05   15.760
## 323 2014-07-06   15.664
## 324 2014-07-07   16.237
## 325 2014-07-08   16.237
## 326 2014-07-09   16.237
## 327 2014-07-10   16.523
print(oyssdd)
##           Date min_temp
## 201 2014-03-06    8.082
## 202 2014-03-07    8.282
## 203 2014-03-08    8.382
## 204 2014-03-09    8.382
## 205 2014-03-10    8.382
## 206 2014-03-11    8.879
## 207 2014-03-12    8.779
## 208 2014-03-13    8.779
## 209 2014-03-14    8.680
## 210 2014-03-15    8.779
## 211 2014-03-16    8.879
## 212 2014-03-17    8.779
## 213 2014-03-18    8.779
## 214 2014-03-19    8.879
## 215 2014-03-20    8.680
## 216 2014-03-21    8.779
## 217 2014-03-22    8.879
## 218 2014-03-23    8.879
## 219 2014-03-24    8.978
## 220 2014-03-25    8.978
## 221 2014-03-26    9.176
## 222 2014-03-27    9.176
## 223 2014-03-28    9.275
## 224 2014-03-29    9.275
## 225 2014-03-30    9.176
## 226 2014-03-31    9.275
## 227 2014-04-01    9.275
## 228 2014-04-02    9.373
## 229 2014-04-03    9.571
## 230 2014-04-04    9.571
## 231 2014-04-05    9.669
## 232 2014-04-06    9.571
## 233 2014-04-07    9.669
## 234 2014-04-08    9.669
## 235 2014-04-09    9.866
## 236 2014-04-10    9.866
## 237 2014-04-11   10.063
## 238 2014-04-12   10.161
## 239 2014-04-13   10.455
## 240 2014-04-14   10.553
## 241 2014-04-15   10.748
## 242 2014-04-16   10.944
## 243 2014-04-17   10.748
## 244 2014-04-18   10.651
## 245 2014-04-19   10.651
## 246 2014-04-20   10.651
## 247 2014-04-21   10.553
## 248 2014-04-22   10.553
## 249 2014-04-23   10.651
## 250 2014-04-24   10.651
## 251 2014-04-25   10.846
## 252 2014-04-26   10.748
## 253 2014-04-27   10.748
## 254 2014-04-28   10.846
## 255 2014-04-29   10.944
## 256 2014-04-30   11.139
## 257 2014-05-01   11.236
## 258 2014-05-02   11.431
## 259 2014-05-03   12.013
## 260 2014-05-04   11.819
## 261 2014-05-05   11.722
## 262 2014-05-06   11.722
## 263 2014-05-07   11.625
## 264 2014-05-08   11.625
## 265 2014-05-09   11.625
## 266 2014-05-10   11.819
## 267 2014-05-11   11.916
## 268 2014-05-12   12.013
## 269 2014-05-13   12.013
## 270 2014-05-14   12.690
## 271 2014-05-15   12.594
## 272 2014-05-16   12.690
## 273 2014-05-17   13.076
## 274 2014-05-18   13.269
## 275 2014-05-19   13.173
## 276 2014-05-20   13.269
## 277 2014-05-21   13.269
## 278 2014-05-22   13.461
## 279 2014-05-23   13.173
## 280 2014-05-24   13.558
## 281 2014-05-25   13.461
## 282 2014-05-26   13.558
## 283 2014-05-27   13.558
## 284 2014-05-28   13.461
## 285 2014-05-29   13.654
## 286 2014-05-30   13.654
## 287 2014-05-31   13.846
## 288 2014-06-01   13.750
## 289 2014-06-02   14.038
## 290 2014-06-03   14.038
## 291 2014-06-04   14.038
## 292 2014-06-05   14.230
## 293 2014-06-06   13.942
## 294 2014-06-07   14.134
## 295 2014-06-08   14.038
## 296 2014-06-09   13.942
## 297 2014-06-10   14.613
## 298 2014-06-11   13.942
## 299 2014-06-12   14.613
## 300 2014-06-13   14.900
## 301 2014-06-14   14.804
## 302 2014-06-15   14.709
## 303 2014-06-16   14.421
## 304 2014-06-17   14.421
## 305 2014-06-18   14.421
## 306 2014-06-19   14.517
#once these subsets are created we need to create a column of the difference between the 8 C minimum
#and the daily minimum temp for each subsets
oyshndd$tempdiff<-oyshndd$min_temp-8
oyssdd$tempdiff<-oyssdd$min_temp-8
#use this temp diff column to create the degree days between 8C minimum and the peak threshold
colSums(oyshndd[,-1])
## min_temp tempdiff 
##     1529      513
colSums(oyssdd[,-1])
## min_temp tempdiff 
##   1202.2    354.2
#we generate this same info for all pops at all sites
fiddd<-ddply(fidmintemp,.(Date),subset,min_temp>=8)
fiddd<-fidmintemp[c(fidmintemp$Date>="2014-03-06"),]
View(fiddd)
fidhndd<-fiddd[c(fiddd$Date<="2014-08-08"),]
fidsdd<-fiddd[c(fiddd$Date<="2014-07-11"),]
View(fidhndd)
View(fidsdd)
fidhndd$tempdiff<-fidhndd$min_temp-8
fidsdd$tempdiff<-fidsdd$min_temp-8
colSums(fidhndd[,-1])
## min_temp tempdiff 
##   1697.7    449.7
colSums(fidsdd[,-1])
## min_temp tempdiff 
##   1328.6    304.6
mandd<-ddply(manmintemp,.(Date),subset,min_temp>=8)
mandd<-manmintemp[c(manmintemp$Date>="2014-03-06"),]
View(mandd)
manhsdd<-mandd[c(mandd$Date<="2014-08-06"),]
manndd<-mandd[c(mandd$Date<="2014-06-25"),]
View(manhsdd)
View(manndd)
manhsdd$tempdiff<-manhsdd$min_temp-8
manndd$tempdiff<-manndd$min_temp-8
colSums(manhsdd[,-1])
## min_temp tempdiff 
##   1723.7    491.7
colSums(manndd[,-1])
## min_temp tempdiff 
##   1141.6    245.6
#due to how R works its easier to just copy these numbers and create a data frame to merge with the peak threshold info
DegreeDays<-c("512.999","512.999","354.156","453.021","453.021","307.894","377.561","175.322","377.561")
Pop<-c("H","N","S")
Site<-c("Oyster Bay","Oyster Bay","Oyster Bay","Fidalgo","Fidalgo","Fidalgo","Manchester","Manchester","Manchester")
Degree<-data.frame(Site,Pop,DegreeDays)
#onces the Degree data frame is created it can be merged with the peakthresh2 data frame to show degree days and time to peak in the same table
peakthresh3<-merge(peakthresh2,Degree,by.x=c("Site","Pop"),by.y=c("Site","Pop"),all=T)
print(peakthresh3)
##          Site Pop  Peak_Date Brooders Threshold Date Days_to_Peak
## 1     Fidalgo   H 2014-08-08        3     2014-06-03      66 days
## 2     Fidalgo   N 2014-08-08        5     2014-06-03      66 days
## 3     Fidalgo   S 2014-07-11       11     2014-06-03      38 days
## 4  Manchester   H 2014-08-06        2     2014-06-08      59 days
## 5  Manchester   N 2014-06-25        1     2014-06-08      17 days
## 6  Manchester   S 2014-08-06        4     2014-06-08      59 days
## 7  Oyster Bay   H 2014-07-10        6     2014-05-14      57 days
## 8  Oyster Bay   N 2014-07-10        8     2014-05-14      57 days
## 9  Oyster Bay   S 2014-06-19       11     2014-05-14      36 days
## 10 Oyster Bay   S 2014-06-26       11     2014-05-14      43 days
##    DegreeDays
## 1     453.021
## 2     453.021
## 3     307.894
## 4     377.561
## 5     175.322
## 6     377.561
## 7     512.999
## 8     512.999
## 9     354.156
## 10    354.156
#now we need to make a graph because nothing is good unless its a graph
#first we merge the three longest time frame tempdiff to create a data frame that works with ggplot2
of<-merge(oyshndd,fidhndd,by="Date",all=T,incomparables="0")
dddf<-merge(of,manhsdd,by="Date",all=T,incomparables="0")
#we need to clean up the NAs produced so that these can be graphed in ggplot2
dddf[is.na(dddf)]<-0
#Now we rename the columns to meaningful titles
dddf<-rename(dddf,c('Date'='Date','min_temp.x'='oysmin','tempdiff.x'='oystempdiff','min_temp.y'='fidmin','tempdiff.y'='fidtempdiff','min_temp'='manmin','tempdiff'='mantempdiff'))
#check the data frame to make sure that everything aligns to the X axis dates of interest with the right tempdiff numbers
print(dddf)
##           Date oysmin oystempdiff fidmin fidtempdiff manmin mantempdiff
## 1   2014-03-06  8.082       0.082  7.079      -0.921  8.082      0.0820
## 2   2014-03-07  8.282       0.282  7.280      -0.720  8.082      0.0820
## 3   2014-03-08  8.382       0.382  7.582      -0.418  8.082      0.0820
## 4   2014-03-09  8.382       0.382  7.381      -0.619  8.282      0.2820
## 5   2014-03-10  8.382       0.382  7.582      -0.418  8.282      0.2820
## 6   2014-03-11  8.879       0.879  7.782      -0.218  8.382      0.3820
## 7   2014-03-12  8.779       0.779  8.082       0.082  8.680      0.6800
## 8   2014-03-13  8.779       0.779  8.581       0.581  8.879      0.8790
## 9   2014-03-14  8.680       0.680  7.782      -0.218  8.680      0.6800
## 10  2014-03-15  8.779       0.779  7.782      -0.218  8.581      0.5810
## 11  2014-03-16  8.879       0.879  7.983      -0.017  8.481      0.4810
## 12  2014-03-17  8.779       0.779  7.682      -0.318  8.481      0.4810
## 13  2014-03-18  8.779       0.779  7.682      -0.318  8.581      0.5810
## 14  2014-03-19  8.879       0.879  7.882      -0.118  8.481      0.4810
## 15  2014-03-20  8.680       0.680  7.782      -0.218  8.382      0.3820
## 16  2014-03-21  8.779       0.779  8.182       0.182  8.481      0.4810
## 17  2014-03-22  8.879       0.879  7.983      -0.017  8.481      0.4810
## 18  2014-03-23  8.879       0.879  7.983      -0.017  8.581      0.5810
## 19  2014-03-24  8.978       0.978  8.182       0.182  8.779      0.7790
## 20  2014-03-25  8.978       0.978  8.082       0.082  8.879      0.8790
## 21  2014-03-26  9.176       1.176  7.882      -0.118  8.581      0.5810
## 22  2014-03-27  9.176       1.176  8.082       0.082  8.581      0.5810
## 23  2014-03-28  9.275       1.275  8.282       0.282  8.581      0.5810
## 24  2014-03-29  9.275       1.275  8.082       0.082  8.431      0.4315
## 25  2014-03-30  9.176       1.176  8.282       0.282  8.382      0.3820
## 26  2014-03-31  9.275       1.275  7.983      -0.017  8.481      0.4810
## 27  2014-04-01  9.275       1.275  8.581       0.581  8.581      0.5810
## 28  2014-04-02  9.373       1.373  8.481       0.481  8.680      0.6800
## 29  2014-04-03  9.571       1.571  8.481       0.481  8.680      0.6800
## 30  2014-04-04  9.571       1.571  8.282       0.282  8.581      0.5810
## 31  2014-04-05  9.669       1.669  8.382       0.382  8.680      0.6800
## 32  2014-04-06  9.571       1.571  8.382       0.382  8.779      0.7790
## 33  2014-04-07  9.669       1.669  8.680       0.680  8.978      0.9780
## 34  2014-04-08  9.669       1.669  8.879       0.879  9.127      1.1265
## 35  2014-04-09  9.866       1.866  8.680       0.680  9.176      1.1760
## 36  2014-04-10  9.866       1.866  8.779       0.779  9.669      1.6690
## 37  2014-04-11 10.063       2.063  9.077       1.077 10.161      2.1610
## 38  2014-04-12 10.161       2.161  9.176       1.176 10.602      2.6020
## 39  2014-04-13 10.455       2.455  9.373       1.373 10.357      2.3570
## 40  2014-04-14 10.553       2.553  9.669       1.669 10.161      2.1610
## 41  2014-04-15 10.748       2.748  9.176       1.176 10.161      2.1610
## 42  2014-04-16 10.944       2.944  9.275       1.275  9.768      1.7680
## 43  2014-04-17 10.748       2.748  9.472       1.472  9.275      1.2750
## 44  2014-04-18 10.651       2.651  9.077       1.077  9.472      1.4720
## 45  2014-04-19 10.651       2.651  9.275       1.275  9.275      1.2750
## 46  2014-04-20 10.651       2.651  8.978       0.978  9.275      1.2750
## 47  2014-04-21 10.553       2.553  9.275       1.275  9.275      1.2750
## 48  2014-04-22 10.553       2.553  9.176       1.176  9.373      1.3730
## 49  2014-04-23 10.651       2.651  9.571       1.571  9.472      1.4720
## 50  2014-04-24 10.651       2.651  9.275       1.275  9.472      1.4720
## 51  2014-04-25 10.846       2.846  9.472       1.472  9.472      1.4720
## 52  2014-04-26 10.748       2.748  9.472       1.472  9.373      1.3730
## 53  2014-04-27 10.748       2.748  9.275       1.275  9.176      1.1760
## 54  2014-04-28 10.846       2.846  9.373       1.373  9.275      1.2750
## 55  2014-04-29 10.944       2.944 10.161       2.161  9.275      1.2750
## 56  2014-04-30 11.139       3.139 10.357       2.357  9.275      1.2750
## 57  2014-05-01 11.236       3.236 10.259       2.259  9.768      1.7680
## 58  2014-05-02 11.431       3.431 10.161       2.161  9.965      1.9650
## 59  2014-05-03 12.013       4.013  9.866       1.866  9.669      1.6690
## 60  2014-05-04 11.819       3.819  9.965       1.965  9.669      1.6690
## 61  2014-05-05 11.722       3.722  9.965       1.965  9.768      1.7680
## 62  2014-05-06 11.722       3.722 10.063       2.063  9.866      1.8660
## 63  2014-05-07 11.625       3.625 10.357       2.357 10.161      2.1610
## 64  2014-05-08 11.625       3.625 10.259       2.259  9.965      1.9650
## 65  2014-05-09 11.625       3.625  9.965       1.965 10.063      2.0630
## 66  2014-05-10 11.819       3.819 10.259       2.259  9.866      1.8660
## 67  2014-05-11 11.916       3.916 10.553       2.553  9.965      1.9650
## 68  2014-05-12 12.013       4.013 11.041       3.041 10.357      2.3570
## 69  2014-05-13 12.013       4.013 12.304       4.304 11.285      3.2850
## 70  2014-05-14 12.690       4.690 12.594       4.594 11.819      3.8190
## 71  2014-05-15 12.594       4.594 11.916       3.916 11.625      3.6250
## 72  2014-05-16 12.690       4.690 11.041       3.041 11.041      3.0410
## 73  2014-05-17 13.076       5.076 11.041       3.041 10.504      2.5040
## 74  2014-05-18 13.269       5.269 11.139       3.139 10.553      2.5530
## 75  2014-05-19 13.173       5.173 10.944       2.944 10.602      2.6020
## 76  2014-05-20 13.269       5.269 11.041       3.041 10.651      2.6510
## 77  2014-05-21 13.269       5.269 10.748       2.748 10.944      2.9440
## 78  2014-05-22 13.461       5.461 11.139       3.139 11.674      3.6735
## 79  2014-05-23 13.173       5.173 10.846       2.846 11.916      3.9160
## 80  2014-05-24 13.558       5.558 10.748       2.748 11.431      3.4310
## 81  2014-05-25 13.461       5.461 11.041       3.041 11.625      3.6250
## 82  2014-05-26 13.558       5.558 10.846       2.846 11.479      3.4795
## 83  2014-05-27 13.558       5.558 10.748       2.748 11.041      3.0410
## 84  2014-05-28 13.461       5.461 11.528       3.528 11.236      3.2360
## 85  2014-05-29 13.654       5.654 10.944       2.944 11.041      3.0410
## 86  2014-05-30 13.654       5.654 11.041       3.041 10.846      2.8460
## 87  2014-05-31 13.846       5.846 11.916       3.916 11.139      3.1390
## 88  2014-06-01 13.750       5.750 11.722       3.722 11.236      3.2360
## 89  2014-06-02 14.038       6.038 11.819       3.819 11.334      3.3340
## 90  2014-06-03 14.038       6.038 13.173       5.173 11.528      3.5280
## 91  2014-06-04 14.038       6.038 12.883       4.883 11.528      3.5280
## 92  2014-06-05 14.230       6.230 13.558       5.558 11.625      3.6250
## 93  2014-06-06 13.942       5.942 14.613       6.613 12.013      4.0130
## 94  2014-06-07 14.134       6.134 15.091       7.091 12.690      4.6900
## 95  2014-06-08 14.038       6.038 13.461       5.461 13.750      5.7500
## 96  2014-06-09 13.942       5.942 13.365       5.365 14.182      6.1820
## 97  2014-06-10 14.613       6.613 12.690       4.690 13.654      5.6540
## 98  2014-06-11 13.942       5.942 12.594       4.594 13.558      5.5580
## 99  2014-06-12 14.613       6.613 12.013       4.013 12.980      4.9800
## 100 2014-06-13 14.900       6.900 11.431       3.431 12.449      4.4490
## 101 2014-06-14 14.804       6.804 11.139       3.139 12.013      4.0130
## 102 2014-06-15 14.709       6.709 11.041       3.041 11.674      3.6735
## 103 2014-06-16 14.421       6.421 10.944       2.944 11.722      3.7220
## 104 2014-06-17 14.421       6.421 10.846       2.846 11.819      3.8190
## 105 2014-06-18 14.421       6.421 10.748       2.748 11.722      3.7220
## 106 2014-06-19 14.517       6.517 10.651       2.651 11.819      3.8190
## 107 2014-06-20 14.517       6.517 10.944       2.944 12.013      4.0130
## 108 2014-06-21 14.996       6.996 11.334       3.334 12.013      4.0130
## 109 2014-06-22 14.900       6.900 12.110       4.110 12.110      4.1100
## 110 2014-06-23 14.804       6.804 12.110       4.110 12.883      4.8830
## 111 2014-06-24 14.804       6.804 11.528       3.528 13.173      5.1730
## 112 2014-06-25 15.282       7.282 12.013       4.013 13.076      5.0760
## 113 2014-06-26 15.378       7.378 13.076       5.076 12.931      4.9315
## 114 2014-06-27 15.473       7.473 12.401       4.401 12.497      4.4970
## 115 2014-06-28 15.664       7.664 11.916       3.916 12.304      4.3040
## 116 2014-06-29 15.569       7.569 11.819       3.819 12.304      4.3040
## 117 2014-06-30 15.569       7.569 11.722       3.722 12.207      4.2070
## 118 2014-07-01 15.664       7.664 12.110       4.110 12.594      4.5940
## 119 2014-07-02 15.569       7.569 11.625       3.625 13.125      5.1245
## 120 2014-07-03 15.855       7.855 11.334       3.334 13.269      5.2690
## 121 2014-07-04 16.141       8.141 11.722       3.722 13.990      5.9900
## 122 2014-07-05 15.760       7.760 12.690       4.690 14.517      6.5170
## 123 2014-07-06 15.664       7.664 13.076       5.076 14.996      6.9960
## 124 2014-07-07 16.237       8.237 13.654       5.654 15.569      7.5690
## 125 2014-07-08 16.237       8.237 14.613       6.613 15.617      7.6165
## 126 2014-07-09 16.237       8.237 15.473       7.473 15.808      7.8075
## 127 2014-07-10 16.523       8.523 16.427       8.427 15.282      7.2820
## 128 2014-07-11  0.000       0.000 16.332       8.332 14.517      6.5170
## 129 2014-07-12  0.000       0.000 14.613       6.613 14.421      6.4210
## 130 2014-07-13  0.000       0.000 13.269       5.269 14.038      6.0380
## 131 2014-07-14  0.000       0.000 12.690       4.690 13.750      5.7500
## 132 2014-07-15  0.000       0.000 12.497       4.497 13.654      5.6540
## 133 2014-07-16  0.000       0.000 12.401       4.401 13.654      5.6540
## 134 2014-07-17  0.000       0.000 12.110       4.110 13.846      5.8460
## 135 2014-07-18  0.000       0.000 12.110       4.110 13.750      5.7500
## 136 2014-07-19  0.000       0.000 12.207       4.207 13.365      5.3650
## 137 2014-07-20  0.000       0.000 12.401       4.401 13.173      5.1730
## 138 2014-07-21  0.000       0.000 12.594       4.594 13.461      5.4610
## 139 2014-07-22  0.000       0.000 12.980       4.980 13.365      5.3650
## 140 2014-07-23  0.000       0.000 12.594       4.594 13.173      5.1730
## 141 2014-07-24  0.000       0.000 11.916       3.916 13.125      5.1245
## 142 2014-07-25  0.000       0.000 11.916       3.916 13.076      5.0760
## 143 2014-07-26  0.000       0.000 12.401       4.401 13.269      5.2690
## 144 2014-07-27  0.000       0.000 12.110       4.110 13.461      5.4610
## 145 2014-07-28  0.000       0.000 12.401       4.401 13.558      5.5580
## 146 2014-07-29  0.000       0.000 12.883       4.883 13.750      5.7500
## 147 2014-07-30  0.000       0.000 12.013       4.013 13.942      5.9420
## 148 2014-07-31  0.000       0.000 12.980       4.980 14.325      6.3250
## 149 2014-08-01  0.000       0.000 13.654       5.654 14.469      6.4690
## 150 2014-08-02  0.000       0.000 14.804       6.804 14.613      6.6130
## 151 2014-08-03  0.000       0.000 15.664       7.664 14.709      6.7090
## 152 2014-08-04  0.000       0.000 15.855       7.855 14.709      6.7090
## 153 2014-08-05  0.000       0.000 15.473       7.473 14.996      6.9960
## 154 2014-08-06  0.000       0.000 14.996       6.996 14.900      6.9000
## 155 2014-08-07  0.000       0.000 14.134       6.134  0.000      0.0000
## 156 2014-08-08  0.000       0.000 13.461       5.461  0.000      0.0000
#using ggplot and cumsum(cumulativesum) we can create cumulative lines of the tempdiffs
#we have to manually add points to the line through annotate to show the threshold temps and peak brooding for each pop
ggplot(dddf)+
  geom_line(aes(x=Date,y=cumsum(dddf$oystempdiff)),color="orange",size=2)+
  geom_line(aes(x=Date,y=cumsum(dddf$fidtempdiff)),color="purple",size=2)+
  geom_line(aes(x=Date,y=cumsum(dddf$mantempdif)),color="red",size=2)+
  annotate("point",x=as.Date("2014-06-03",'%Y-%m-%d'),y=133,size=5,color='red',pch=15)+
  annotate("point",x=as.Date("2014-05-14",'%Y-%m-%d'),y=143,size=5,color='red',pch=15)+
  annotate("point",x=as.Date("2014-06-08",'%Y-%m-%d'),y=113,size=5,color='red',pch=15)+
  annotate("point",x=as.Date("2014-08-08",'%Y-%m-%d'),y=460,size=10,color='blue',pch=13)+
  annotate("point",x=as.Date("2014-08-06",'%Y-%m-%d'),y=383,size=10,color='blue',pch=13)+
  annotate("point",x=as.Date("2014-07-10",'%Y-%m-%d'),y=520,size=10,color='blue',pch=13)+
  annotate("point",x=as.Date("2014-08-08",'%Y-%m-%d'),y=453.021,size=10,color='purple',pch=13)+
  annotate("point",x=as.Date("2014-06-25",'%Y-%m-%d'),y=175.322,size=10,color='purple',pch=13)+
  annotate("point",x=as.Date("2014-07-10",'%Y-%m-%d'),y=512.999,size=10,color='purple',pch=13)+
  annotate("point",x=as.Date("2014-07-11",'%Y-%m-%d'),y=307.894,size=10,color='orange',pch=13)+
  annotate("point",x=as.Date("2014-08-06",'%Y-%m-%d'),y=377.561,size=10,color='orange',pch=13)+
  annotate("point",x=as.Date("2014-06-19",'%Y-%m-%d'),y=354.156,size=10,color='orange',pch=13)+
  theme_bw()+
  labs(title="Degree Days compared between Sites and Populations",x="Date",y="Cumulative Degrees over 8 C Minimum")
plot of chunk unnamed-chunk-1
#each red square represents the date when the threshold 12.5 C spawning temp was reached
#the orange, purple, and red lines are Oyster Bay, Fidalgo, and Manchester Sites respectfull
#the orange, blue, and purple crosshairs are peak brooding for Oyster Bay, Dabob, and Fidalgo pops at each site respectfully
#

No comments:

Post a Comment