Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HIDDEN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sPlot
HIDDEN
Commits
e723adc4
Commit
e723adc4
authored
4 years ago
by
Francesco Sabatini
Browse files
Options
Downloads
Patches
Plain Diff
Prepared ALSO data based on species covers
parent
fb550be0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
00_Mesobromion_DataPreparation.R
+120
-71
120 additions, 71 deletions
00_Mesobromion_DataPreparation.R
with
120 additions
and
71 deletions
00_Mesobromion_DataPreparation.R
+
120
−
71
View file @
e723adc4
...
...
@@ -68,13 +68,15 @@ alltry <- TRY.all.mean.sd.3.by.genus.species.tree %>%
dplyr
::
select
(
-
Wood.vessel.length.mean
,
-
StemDens.mean
,
-
Stem.cond.dens.mean
)
%>%
rename_all
(
.funs
=~
gsub
(
pattern
=
".mean$"
,
replacement
=
""
,
x
=
.
))
traits
<-
traits0
%>%
all.
traits
<-
traits0
%>%
ungroup
()
%>%
#dplyr::select(species, species0) %>%
left_join
(
alltry
%>%
rename
(
species
=
StandSpeciesName
),
by
=
"species"
)
%>%
by
=
"species"
)
traits
<-
all.traits
%>%
filter
(
!
is.na
(
LeafArea
))
dim
(
all.traits
)
#[1] 907 81
dim
(
traits
)
#[1] 805 2
...
...
@@ -159,71 +161,76 @@ traits <- traits %>%
filter
(
species0
%in%
colnames
(
species
))
#recode binary traits to nominal
colnames
(
traits
)[
which
(
colnames
(
traits
)
==
"LBE_D_plurienn_hapaxanth"
)]
<-
"LEB_D_plurienn_hapaxanth"
traits
<-
traits
%>%
mutate
(
BLU_KL_NEKTAR_HONIG_INSEKTEN
=
replace
(
BLU_KL_NEKTAR_HONIG_INSEKTEN
,
list
=
species0
%in%
c
(
"Convallaria_majalis"
,
"Maianthemum_bifolium"
),
values
=
0
))
traits
<-
traits
%>%
as.tbl
()
%>%
dplyr
::
select
(
-
starts_with
(
"BL_FORM"
),
-
starts_with
(
"REPR_T"
),
-
starts_with
(
"BLU_KL"
),
-
starts_with
(
"STRAT_T"
),
-
starts_with
(
"BL_AUSD"
))
%>%
left_join
(
traits
%>%
dplyr
::
select
(
species0
,
`BL_AUSD_immergrün`
:
`BL_AUSD_überwinternd_grün`
,
REPR_T_Samen_Sporen
:
STRAT_T_SR
)
%>%
gather
(
key
=
Trait
,
value
=
"value"
,
-
species0
)
%>%
separate
(
Trait
,
into
=
c
(
"Trait"
,
"Organ"
,
"Level"
),
sep
=
"_"
,
extra
=
"merge"
)
%>%
unite
(
Trait
,
Trait
,
Organ
)
%>%
filter
(
value
==
1
)
%>%
dplyr
::
select
(
-
value
)
%>%
spread
(
Trait
,
Level
)
%>%
mutate_at
(
.vars
=
vars
(
BL_AUSD
:
STRAT_T
),
.funs
=~
as.factor
(
.
)),
by
=
"species0"
)
## recode traits to numeric
robust.mean
<-
function
(
x1
,
x2
=
NA
,
x3
=
NA
,
x4
=
NA
){
x
<-
c
(
x1
,
x2
,
x3
,
x4
)
if
(
any
(
!
is.na
(
x
))){
mean
(
x
,
na.rm
=
T
)}
else
{
NA
}
recode.traits
<-
function
(
x
){
## recode traits to numeric
#recode binary traits to nominal
robust.mean
<-
function
(
x1
,
x2
=
NA
,
x3
=
NA
,
x4
=
NA
){
x
<-
c
(
x1
,
x2
,
x3
,
x4
)
if
(
any
(
!
is.na
(
x
))){
mean
(
x
,
na.rm
=
T
)}
else
{
NA
}
}
colnames
(
x
)[
which
(
colnames
(
x
)
==
"LBE_D_plurienn_hapaxanth"
)]
<-
"LEB_D_plurienn_hapaxanth"
x
<-
x
%>%
mutate
(
BLU_KL_NEKTAR_HONIG_INSEKTEN
=
replace
(
BLU_KL_NEKTAR_HONIG_INSEKTEN
,
list
=
species0
%in%
c
(
"Convallaria_majalis"
,
"Maianthemum_bifolium"
),
values
=
0
))
x
<-
x
%>%
as.tbl
()
%>%
dplyr
::
select
(
-
starts_with
(
"BL_FORM"
),
-
starts_with
(
"REPR_T"
),
-
starts_with
(
"BLU_KL"
),
-
starts_with
(
"STRAT_T"
),
-
starts_with
(
"BL_AUSD"
))
%>%
left_join
(
x
%>%
dplyr
::
select
(
species0
,
`BL_AUSD_immergrün`
:
`BL_AUSD_überwinternd_grün`
,
REPR_T_Samen_Sporen
:
STRAT_T_SR
)
%>%
gather
(
key
=
Trait
,
value
=
"value"
,
-
species0
)
%>%
separate
(
Trait
,
into
=
c
(
"Trait"
,
"Organ"
,
"Level"
),
sep
=
"_"
,
extra
=
"merge"
)
%>%
unite
(
Trait
,
Trait
,
Organ
)
%>%
filter
(
value
==
1
)
%>%
dplyr
::
select
(
-
value
)
%>%
spread
(
Trait
,
Level
)
%>%
mutate_at
(
.vars
=
vars
(
BL_AUSD
:
STRAT_T
),
.funs
=~
as.factor
(
.
)),
by
=
"species0"
)
out
<-
x
%>%
dplyr
::
select
(
-
starts_with
(
"BL_ANAT"
),
-
starts_with
(
"LEB_D"
),
-
starts_with
(
"ROS_T"
))
%>%
left_join
(
x
%>%
dplyr
::
select
(
species0
,
starts_with
(
"BL_ANAT"
))
%>%
mutate
(
BL_ANAT_helomorph
=
ifelse
(
BL_ANAT_helomorph
==
1
,
1
,
NA
))
%>%
mutate
(
BL_ANAT_hygromorph
=
ifelse
(
BL_ANAT_hygromorph
==
1
,
2
,
NA
))
%>%
mutate
(
BL_ANAT_mesomorph
=
ifelse
(
BL_ANAT_mesomorph
==
1
,
3
,
NA
))
%>%
mutate
(
BL_ANAT_skleromorph
=
ifelse
(
BL_ANAT_skleromorph
==
1
,
4
,
NA
))
%>%
rowwise
()
%>%
mutate
(
BL_ANAT
=
robust.mean
(
BL_ANAT_helomorph
,
BL_ANAT_hygromorph
,
BL_ANAT_mesomorph
,
BL_ANAT_skleromorph
))
%>%
ungroup
()
%>%
dplyr
::
select
(
species0
,
BL_ANAT
,
BL_ANAT_blattsukkulent
),
by
=
"species0"
)
%>%
left_join
(
x
%>%
dplyr
::
select
(
species0
,
starts_with
(
"LEB_D"
))
%>%
rowwise
()
%>%
mutate
(
LEB_D_plurienn
=
max
(
LEB_D_plurienn_pollakanth
+
LEB_D_plurienn_hapaxanth
,
na.rm
=
T
))
%>%
ungroup
()
%>%
mutate
(
LEB_D_plurienn
=
ifelse
(
LEB_D_plurienn
==
1
,
3
,
NA
))
%>%
mutate
(
LEB_D_annuell
=
ifelse
(
LEB_D_annuell
==
1
,
1
,
NA
))
%>%
mutate
(
LEB_D_bienn
=
ifelse
(
LEB_D_bienn
==
1
,
2
,
NA
))
%>%
rowwise
()
%>%
mutate
(
LEB_D
=
robust.mean
(
LEB_D_annuell
,
LEB_D_bienn
,
LEB_D_plurienn
))
%>%
ungroup
()
%>%
dplyr
::
select
(
species0
,
LEB_D
),
by
=
"species0"
)
%>%
left_join
(
x
%>%
dplyr
::
select
(
species0
,
starts_with
(
"ROS_T"
))
%>%
mutate
(
ROS_T
=
ROS_T_Ganzrosettenpflanzen
)
%>%
mutate
(
ROS_T
=
replace
(
ROS_T
,
list
=
ROS_T_Halbrosettenpflanze
==
1
,
values
=
0.5
))
%>%
mutate
(
ROS_T
=
replace
(
ROS_T
,
list
=
ROS_T_rosettenlose.Pflanzen
==
1
,
values
=
0
))
%>%
dplyr
::
select
(
species0
,
ROS_T
),
by
=
"species0"
)
return
(
out
)
}
traits
<-
traits
%>%
dplyr
::
select
(
-
starts_with
(
"BL_ANAT"
),
-
starts_with
(
"LEB_D"
),
-
starts_with
(
"ROS_T"
))
%>%
left_join
(
traits
%>%
dplyr
::
select
(
species0
,
starts_with
(
"BL_ANAT"
))
%>%
mutate
(
BL_ANAT_helomorph
=
ifelse
(
BL_ANAT_helomorph
==
1
,
1
,
NA
))
%>%
mutate
(
BL_ANAT_hygromorph
=
ifelse
(
BL_ANAT_hygromorph
==
1
,
2
,
NA
))
%>%
mutate
(
BL_ANAT_mesomorph
=
ifelse
(
BL_ANAT_mesomorph
==
1
,
3
,
NA
))
%>%
mutate
(
BL_ANAT_skleromorph
=
ifelse
(
BL_ANAT_skleromorph
==
1
,
4
,
NA
))
%>%
rowwise
()
%>%
mutate
(
BL_ANAT
=
robust.mean
(
BL_ANAT_helomorph
,
BL_ANAT_hygromorph
,
BL_ANAT_mesomorph
,
BL_ANAT_skleromorph
))
%>%
ungroup
()
%>%
dplyr
::
select
(
species0
,
BL_ANAT
,
BL_ANAT_blattsukkulent
),
by
=
"species0"
)
%>%
left_join
(
traits
%>%
dplyr
::
select
(
species0
,
starts_with
(
"LEB_D"
))
%>%
rowwise
()
%>%
mutate
(
LEB_D_plurienn
=
max
(
LEB_D_plurienn_pollakanth
+
LEB_D_plurienn_hapaxanth
,
na.rm
=
T
))
%>%
ungroup
()
%>%
mutate
(
LEB_D_plurienn
=
ifelse
(
LEB_D_plurienn
==
1
,
3
,
NA
))
%>%
mutate
(
LEB_D_annuell
=
ifelse
(
LEB_D_annuell
==
1
,
1
,
NA
))
%>%
mutate
(
LEB_D_bienn
=
ifelse
(
LEB_D_bienn
==
1
,
2
,
NA
))
%>%
rowwise
()
%>%
mutate
(
LEB_D
=
robust.mean
(
LEB_D_annuell
,
LEB_D_bienn
,
LEB_D_plurienn
))
%>%
ungroup
()
%>%
dplyr
::
select
(
species0
,
LEB_D
),
by
=
"species0"
)
%>%
left_join
(
traits
%>%
dplyr
::
select
(
species0
,
starts_with
(
"ROS_T"
))
%>%
mutate
(
ROS_T
=
ROS_T_Ganzrosettenpflanzen
)
%>%
mutate
(
ROS_T
=
replace
(
ROS_T
,
list
=
ROS_T_Halbrosettenpflanze
==
1
,
values
=
0.5
))
%>%
mutate
(
ROS_T
=
replace
(
ROS_T
,
list
=
ROS_T_rosettenlose.Pflanzen
==
1
,
values
=
0
))
%>%
dplyr
::
select
(
species0
,
ROS_T
),
by
=
"species0"
)
traits
<-
recode.traits
(
traits
)
### ordered factors
...
...
@@ -279,8 +286,9 @@ env <- env %>%
##export for Valerio
write_delim
(
species
,
path
=
"_data/Mesobromion/species.out.10perc.txt"
,
delim
=
"\t"
)
write_delim
(
traits
,
path
=
"_data/Mesobromion/traits.out.10perc.txt"
,
delim
=
"\t"
)
write_delim
(
env
,
path
=
"_data/Mesobromion/env.10perc.txt"
,
delim
=
"\t"
)
write_delim
(
traits
,
path
=
"_data/Mesobromion/traits.out.10perc.cov.txt"
,
delim
=
"\t"
)
write_delim
(
env
,
path
=
"_data/Mesobromion/env.10perc.cov.txt"
,
delim
=
"\t"
)
## version without missing species
empty
<-
which
(
colSums
(
species
[,
-1
])
==
0
)
...
...
@@ -290,13 +298,54 @@ species_nozero <- species[,-(empty+1)]
write_delim
(
species_nozero
,
path
=
"_data/Mesobromion/species.out.10perc_nozero.txt"
,
delim
=
"\t"
)
write_delim
(
traits_nozero
,
path
=
"_data/Mesobromion/traits.out.10perc_nozero.txt"
,
delim
=
"\t"
)
write_delim
(
species
%>%
dplyr
::
select
(
RELEVE_NR
),
path
=
"_derived/Mesobromion/ReleveList.txt"
,
delim
=
"\t"
)
### version with cover values ### 4/08/2020
species.proz
<-
read_csv
(
"_data/Mesobromion/GVRD_Mes2_proz.csv"
,
locale
=
locale
(
encoding
=
'latin1'
))
species.proz
$
RELEVE_NR
<-
env0
$
RELEVE_NR
species.proz
<-
species.proz
%>%
filter
(
RELEVE_NR
%in%
(
species
%>%
pull
(
RELEVE_NR
)))
%>%
#transform percentage cover to relative.cover
mutate
(
sumVar
=
rowSums
(
.
[
-1
]))
%>%
mutate_at
(
.vars
=
vars
(
-
RELEVE_NR
),
.funs
=~
.
/
sumVar
)
%>%
dplyr
::
select
(
-
sumVar
)
%>%
## delete species not appearing in any plot
dplyr
::
select
(
colnames
(
.
)[
which
(
colSums
(
.
)
!=
0
)])
dim
(
species.proz
)
#[1] 558 533
write_delim
(
species.proz
,
path
=
"_data/Mesobromion/species.out.10perc.cov.txt"
,
delim
=
"\t"
)
## align traits to species in species.proz
traits.proz
<-
recode.traits
(
all.traits
)
traits.proz
<-
data.frame
(
species
=
colnames
(
species.proz
)[
-1
]
)
%>%
### clean species names in both data.frames
mutate
(
species0
=
as.character
(
species
))
%>%
rowwise
()
%>%
# quick and dirty clean up names
mutate
(
species
=
gsub
(
pattern
=
"_agg_|_x_|_spec$|_agg$|_s_|_Sec_|__"
,
replacement
=
"_"
,
x
=
species
))
%>%
mutate
(
species
=
gsub
(
pattern
=
"_$"
,
replacement
=
""
,
x
=
species
))
%>%
mutate
(
species
=
ifelse
(
is.na
(
word
(
species
,
1
,
2
)),
species
,
word
(
species
,
1
,
2
)))
%>%
ungroup
()
%>%
left_join
(
traits.proz
%>%
mutate
(
species
=
species0
)
%>%
rowwise
()
%>%
mutate
(
species
=
gsub
(
pattern
=
"_agg_|_x_|_spec$|_agg$|_s_|_Sec_|__"
,
replacement
=
"_"
,
x
=
species
))
%>%
mutate
(
species
=
gsub
(
pattern
=
"_$"
,
replacement
=
""
,
x
=
species
))
%>%
mutate
(
species
=
ifelse
(
is.na
(
word
(
species
,
1
,
2
)),
species
,
word
(
species
,
1
,
2
)))
%>%
ungroup
()
%>%
dplyr
::
select
(
-
species0
),
by
=
"species"
)
%>%
dplyr
::
select
(
-
species
)
%>%
dplyr
::
select
(
`species0`
,
everything
())
##check for species without trait info
traits.proz
%>%
filter_at
(
.vars
=
vars
(
-
"species0"
),
all_vars
(
is.na
(
.
)))
%>%
dim
()
## [1] 16 53 # species with no trait info
write_delim
(
traits.cov
,
path
=
"_data/Mesobromion/traits.out.10perc.cov.txt"
,
delim
=
"\t"
)
#### CORRELATION BETWEEN FUZZY WEIGHTED AND BEALS MATRICES
#### WAS RUN IN THE CLUSTER WITH THE SCRIPT 01b_MesobromionCluster.R
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment