# THA_breedcomp.R
# [arthurp] 18-07-2017
# R version: R-3.5.3
# optiSel version: 2.0.2
# RStudio version: 1.1.453
# Dataset: thai_pedigrees.csv (2018)
#
getwd()
library(optiSel)
# library(ggplot2)
all <- read.csv("thai_pedigrees.csv",na.strings="")
ped<-data.frame(all$Indiv, all$Sire, all$Dam, all$Sex, all$Breed, all$Born)
colnames(ped) <- c("Indiv","Sire", "Dam", "Sex", "Breed", "Born")
Pedig<-prePed(ped)
#
use  <- Pedig$Breed=="THA" & Pedig$Born %in% (1995:2017)
cont <- pedBreedComp(Pedig, thisBreed="THA")
contByYear <- conttac(cont, cohort=Pedig$Born, use=use, mincont = 0.01)
#
# ggplot(contByYear, aes(x=Year, y=Contribution, fill=Breed)) + geom_area(color="black")
BC_other<-subset(contByYear, contByYear$Breed=="other")
BC_sia<-subset(contByYear, contByYear$Breed=="SIA")
BC_osh<-subset(contByYear, contByYear$Breed=="OSH")
BC_tha<-subset(contByYear, contByYear$Breed=="native")
#
par(mfrow=c(1,1))
plot(BC_other$Year, BC_other$Contribution, type="n", xlim=c(1995, 2017), ylim=c(0, 1.0), xlab="Year", ylab="Contribution", font=2, font.lab=2 )
lines(BC_other$Year, BC_other$Contribution, type="l", col="red", lwd=1.5 )
lines(BC_osh$Year, BC_osh$Contribution, type="l", col="green", lwd=1.5 )
lines(BC_sia$Year, BC_sia$Contribution, type="l", col="blue", lwd=1.5 )
lines(BC_tha$Year, BC_tha$Contribution, type="l", col="black", lwd=1.5 )
legend(2009, 0.98, c("Other", "Oriental Shorthair", "Siamese", "Thai"), col=c("red", "green", "blue", "black"), lty=1, cex=0.8)
lines(c(1995, 2017), c(0.5, 0.5), type="l", lty=2, lwd=1.5)
#
