-
Notifications
You must be signed in to change notification settings - Fork 1
/
1_Data_exploratory_analysis_RDB.R
119 lines (101 loc) · 5.12 KB
/
1_Data_exploratory_analysis_RDB.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#######################################################################################################
#######################################################################################################
#######################################################################################################
##
##
## Biological sampling optimization (Script SampleOptim)
## Developed by: Patricia Goncalves (IPMA)
## Version for: Regional DataBase (RDB) exchange format
##
## Reference:
## Goncalves, Patricia 2019. SampleOptim a data analysis R-tool to optimize fish sampling for
## biological parameters as input on fish stock assessment.
##
##
## github link: https://github.com/gonpatricia/SampleOptimRDBformat/1_Data_exploratory_analysis_RDB.R
##
##
#######################################################################################################
#######################################################################################################
#######################################################################################################
##Packages:
library(FSA)
library(FSAdata)
library(nlstools)
library(reshape)
library(ggplot2)
library(ggthemes)
library(cvTools)
library(dplyr)
library("robustbase")
library(MASS)
library(psyphy)
library(boot)
library(RCurl)
########################################################################################################
#### Files path and function source:
setwd("~/...") ##Set directory
###Biological sample data (Applied to a period of years)
data_samplebio<- read.table(" .csv",sep=";", header=T)
#########################################################################################################
#### 1. Data Preliminary analysis: (Exploratory analysis)
#### Summary
summary(data_samplebio)
#names(data_samplebio)
table(data_samplebio$Length_class, data_samplebio$month) ##summary of the number of individuals by length class and month
### Number of samples by Port, year and month
nsamples_year_mes<- data_samplebio %>% group_by(Port, month, year) %>% count(date)
#write.table(nsamples_year_mes, "numbersamples_summary_WHB.csv",sep=",")
#### Length classes of the samples by Port, year and month
lengthclass_samples_year_mes<- date_samplebio %>% group_by(Port, month, year) %>% count(Length_class)
#write.table(lengthclass_samples_year_mes, "numberlengthclasses_samples_summary_MAC.csv",sep=",")
########Figure a - length distribution samples by Port by year and month
#Port<-unique(date_samplebio$Port) ## list of Ports names
year<- sort(unique(lengthclass_samples_year_mes$year)) ##list of years on the samples date
for(bb in 1:length(year))
{
plota<- ggplot(lengthclass_samples_year_mes[lengthclass_samples_year_mes$year==year[bb],], aes(x=Length_class,y=n, colour=Port))+xlab("length")+ ylab("number of individuals")+
geom_line()+ theme_classic() + facet_wrap(~factor(month))+
theme(axis.title.y = element_text(size = 14),axis.title.x=element_text(size=14),
axis.line = element_line(size = 0.5),axis.text = element_text(size = 10))
dev.copy(png, paste(year[bb],"_length_distribution_samples_Port_year",".png",sep=""))
print(plota)
dev.off()
}
#### Age of the samples by Port, year and month
age_samples_year_mes<- date_samplebio %>% group_by(Port, month, year) %>% count(Age)
########Figure b - age distribution samples by Port by year and month
#Port<-unique(date_samplebio$Port) ## list of Ports names
year<- sort(unique(age_samples_year_mes$year)) ##list of years on the samples date
for(bb in 1:length(year))
{
plotb<- ggplot(age_samples_year_mes[age_samples_year_mes$year==year[bb],], aes(x=Age,y=n, colour=Port))+xlab("age")+ ylab("number of individuals")+
geom_line()+ theme_classic() + facet_wrap(~factor(month))+
theme(axis.title.y = element_text(size = 14),axis.title.x=element_text(size=14),
axis.line = element_line(size = 0.5),axis.text = element_text(size = 10))
dev.copy(png, paste(year[bb],"_age_distribution_samples_Port_year",".png",sep=""))
print(plotb)
dev.off()
}
## Figura 1 - Length distribution by year
years<- c("2003","2004","2005","2006","2007","2010","2011","2012","2013","2014","2015")
#lines_plot<-round(length(years)/2)
#par(mfrow=c(1,1))
for(nb in 1: length(years))
{
fig1<- hist(date_samplebio$Length_class[date_samplebio$year==years[nb]],xlab="length", ylab="number of individuals", main=years[nb])
dev.copy(png, paste(years[nb],"_length_distribution",".png",sep=""))
nb<- nb+1
dev.off()
}
###Figure 2 - Age distribution by year
for(nb in 1: length(years))
{
fig2<- hist(date_samplebio$Age[date_samplebio$year==years[nb]],xlab="age", ylab="number of individuals", main=years[nb])
dev.copy(png, paste(years[nb],"_age_distribution",".png",sep=""))
nb<- nb+1
dev.off()
}
#########################################################################################################
#########################################################################################################
#########################################################################################################