d <- read.table("dat/boarfish_catch_at_age.csv",header=TRUE,sep=",")
names(d) <- c("age",2007:2013)
d <- melt(d,"age")
names(d) <- c("age","year","oC")
d$year <- as.integer(as.character(d$year))
dcast(d,age ~ year,value.var="oC")
##    age   2007   2008   2009   2010   2011   2012   2013
## 1    1      0      0   1575   2415      0     28    301
## 2    2    352   5488  15043  11229   2894    893   7148
## 3    3   2114  21140  65744  72709  41913   5467 156680
## 4    4  40851 105575 338931 294382  28148  41278  58522
## 5    5  48915 141300 475619 567689  30116 110272  59797
## 6    6  62713 195339 543707 878363 175696 146582  68949
## 7    7  26132 104031 307333 522703 143967 492078 302967
## 8    8  29766  66570 172783 293719 107126 365840 250341
## 9    9  56075  53159 155477 276672  77861 271916 212318
## 10  10  44875  46893 130148 232122  60022 173486 160137
## 11  11  14019  15289  42521  78588  46079  69396  63025
## 12  12  32359  21178  61350 114600  40468  40968  41490
## 13  13   4848  11854  39609  59932  24352  58888  59380
## 14  14  16837  13570  31569  59060  19724  30277  30355
## 15  15 109481 112947 196967 349320 157707 217260 239366
x <- d
x$year <- x$year + 1
x$age <- x$age + 1
names(x)[3] <- c("oC2")
d <- join(d,x)
## Joining by: age, year
d$logC <- log(d$oC2/d$oC)

i <- d$age %in% c(3:12)
dcast(d[i,], age ~ year,value.var = "logC")
##    age 2007    2008     2009     2010    2011     2012    2013
## 1    3   NA -4.0953 -2.48320 -1.57555 -1.3171 -0.63609 -5.1674
## 2    4   NA -3.9108 -2.77463 -1.49911  0.9490  0.01527 -2.3707
## 3    5   NA -1.2410 -1.50520 -0.51578  2.2798 -1.36547 -0.3706
## 4    6   NA -1.3847 -1.34753 -0.61344  1.1728 -1.58253  0.4696
## 5    7   NA -0.5061 -0.45320  0.03940  1.8085 -1.02988 -0.7260
## 6    8   NA -0.9351 -0.50735  0.04531  1.5850 -0.93261  0.6758
## 7    9   NA -0.5799 -0.84824 -0.47080  1.3277 -0.93149  0.5441
## 8   10   NA  0.1788 -0.89538 -0.40077  1.5281 -0.80117  0.5295
## 9   11   NA  1.0767  0.09787  0.50445  1.6169 -0.14512  1.0126
## 10  12   NA -0.4125 -1.38946 -0.99145  0.6637  0.11757  0.5144
ggplot(d[i,],aes(year,logC)) + geom_text(aes(label=age)) + geom_line(aes(group=age))
## Warning: Removed 10 rows containing missing values (geom_text).
## Warning: Removed 10 rows containing missing values (geom_path).

plot of chunk unnamed-chunk-1

i <- d$age %in% c(5:13)
ggplot(d[i,],aes(year,logC)) + geom_text(aes(label=age)) + geom_point() + geom_smooth()
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
## Warning: Removed 9 rows containing missing values (stat_smooth).
## Warning: Removed 9 rows containing missing values (geom_text).
## Warning: Removed 9 rows containing missing values (geom_point).

plot of chunk unnamed-chunk-1