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
ff5dfb1c
Commit
ff5dfb1c
authored
4 years ago
by
Francesco Sabatini
Browse files
Options
Downloads
Patches
Plain Diff
Corrected typo
parent
8aed7b97
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
02_Mesobromion_ExamineOutput.R
+122
-123
122 additions, 123 deletions
02_Mesobromion_ExamineOutput.R
with
122 additions
and
123 deletions
02_Mesobromion_ExamineOutput.R
+
122
−
123
View file @
ff5dfb1c
...
@@ -27,7 +27,7 @@ get.best <- function(x, N, labs){
...
@@ -27,7 +27,7 @@ get.best <- function(x, N, labs){
traits
<-
read_delim
(
"_data/Mesobromion/traits.v2.10perc.txt"
,
delim
=
"\t"
)
traits
<-
read_delim
(
"_data/Mesobromion/traits.v2.10perc.txt"
,
delim
=
"\t"
)
traits
<-
traits
%>%
traits
<-
traits
%>%
rename
(
Sc
h
lerophylly
=
Leaf_Scleroph
)
rename
(
Sclerophylly
=
Leaf_Scleroph
)
#traits.sign.cov <- read_delim("_data/Mesobromion/traits.v2.10perc.cov.sign.txt", delim="\t")
#traits.sign.cov <- read_delim("_data/Mesobromion/traits.v2.10perc.cov.sign.txt", delim="\t")
#traits.sign.pa <- read_delim("_data/Mesobromion/traits.v2.10perc.pa.sign.txt", delim="\t")
#traits.sign.pa <- read_delim("_data/Mesobromion/traits.v2.10perc.pa.sign.txt", delim="\t")
trait.labs
<-
data.frame
(
trait.name
=
colnames
(
traits
)[
-1
])
%>%
trait.labs
<-
data.frame
(
trait.name
=
colnames
(
traits
)[
-1
])
%>%
...
@@ -41,7 +41,7 @@ species.cov <- read_delim("_data/Mesobromion/species.v2.10perc.cov.txt", delim="
...
@@ -41,7 +41,7 @@ species.cov <- read_delim("_data/Mesobromion/species.v2.10perc.cov.txt", delim="
traits
<-
traits
%>%
traits
<-
traits
%>%
as.data.frame
()
%>%
as.data.frame
()
%>%
mutate_at
(
.vars
=
vars
(
Sc
h
lerophylly
,
LifeSpan
,
Rosette
),
mutate_at
(
.vars
=
vars
(
Sclerophylly
,
LifeSpan
,
Rosette
),
.funs
=~
as.ordered
(
.
))
%>%
.funs
=~
as.ordered
(
.
))
%>%
# filter(species0 %in% colnames(species)) %>%
# filter(species0 %in% colnames(species)) %>%
mutate_if
(
~
is.character
(
.
),
.funs
=~
as.factor
(
.
))
%>%
mutate_if
(
~
is.character
(
.
),
.funs
=~
as.factor
(
.
))
%>%
...
@@ -617,7 +617,6 @@ ggsave(filename = "_pics/SXXX_Best_AllCombinations_CI_pa.png", dpi=400,
...
@@ -617,7 +617,6 @@ ggsave(filename = "_pics/SXXX_Best_AllCombinations_CI_pa.png", dpi=400,
#species <- read_delim("_data/Mesobromion/species.out.10perc.txt", delim="\t")
#species <- read_delim("_data/Mesobromion/species.out.10perc.txt", delim="\t")
species.cov
<-
read_delim
(
"_data/Mesobromion/species.v2.10perc.cov.txt"
,
delim
=
"\t"
)
species.cov
<-
read_delim
(
"_data/Mesobromion/species.v2.10perc.cov.txt"
,
delim
=
"\t"
)
#traits <- traits.backup
traits
<-
traits
%>%
traits
<-
traits
%>%
rownames_to_column
(
"species0"
)
%>%
rownames_to_column
(
"species0"
)
%>%
mutate_if
(
.predicate
=~
is.ordered
(
.
),
mutate_if
(
.predicate
=~
is.ordered
(
.
),
...
@@ -954,130 +953,130 @@ PCA3_4.sp <- basemap0 %+% tmp +
...
@@ -954,130 +953,130 @@ PCA3_4.sp <- basemap0 %+% tmp +
ylab
(
paste
(
"PC4 ("
,
varexpl
[
4
],
"%)"
,
sep
=
""
))
ylab
(
paste
(
"PC4 ("
,
varexpl
[
4
],
"%)"
,
sep
=
""
))
ggsave
(
"_pics/
Fig6
a_PCA_Beals_1-2_wSpecies.png"
,
width
=
8
,
height
=
8
,
dpi
=
300
,
PCA1_2.sp
)
ggsave
(
"_pics/
S10
a_PCA_Beals_1-2_wSpecies.png"
,
width
=
8
,
height
=
8
,
dpi
=
300
,
PCA1_2.sp
)
ggsave
(
"_pics/
Fig6
b_PCA_Beals_3-4_wSpecies.png"
,
width
=
8
,
height
=
8
,
dpi
=
300
,
PCA3_4.sp
)
ggsave
(
"_pics/
S10
b_PCA_Beals_3-4_wSpecies.png"
,
width
=
8
,
height
=
8
,
dpi
=
300
,
PCA3_4.sp
)
###### _ ######
###### _ ######
#### 4.2 RDA of Beals ~ FWMs ####
#### 4.2 RDA of Beals ~ FWMs ####
RDA.beals
<-
rda
(
W.beals
~
scores
(
pca.fuzz
,
choices
=
1
:
3
)
$
sites
,
scale
=
F
)
#
RDA.beals <- rda(W.beals ~ scores(pca.fuzz, choices=1:3)$sites, scale=F)
# var explained by CONSTRAINED axes
#
# var explained by CONSTRAINED axes
varexpl
<-
round
((
RDA.beals
$
CCA
$
eig
)
/
(
sum
(
RDA.beals
$
CA
$
eig
)
+
sum
(
RDA.beals
$
CCA
$
eig
))
*
100
,
1
)
#
varexpl <- round((RDA.beals$CCA$eig)/(sum(RDA.beals$CA$eig) + sum(RDA.beals$CCA$eig))*100,1)
#
scores.rda
<-
scores
(
RDA.beals
,
choices
=
1
:
3
)
$
sites
#
#
scores.rda <- scores(RDA.beals, choices = 1:3)$sites #
#scores.rda <- RDA.beals$CA$u[,1:3]
#
#scores.rda <- RDA.beals$CA$u[,1:3]
(
cwms.cor
<-
cor
(
CWM.wide
,
RDA.beals
$
CCA
$
u
[,
1
:
3
]))
#
(cwms.cor <- cor(CWM.wide, RDA.beals$CCA$u[,1:3]))
env.cor
<-
cor
(
env
%>%
#
env.cor <- cor(env %>%
dplyr
::
select
(
Temp
,
Prec
,
pH
=
PHIPHOX
,
C.org
=
ORCDRC
),
#
dplyr::select(Temp, Prec, pH=PHIPHOX, C.org=ORCDRC),
RDA.beals
$
CCA
$
u
[,
1
:
3
],
use
=
"pairwise.complete.obs"
)
#double check
#
RDA.beals$CCA$u[,1:3], use = "pairwise.complete.obs") #double check
(
fuzz.cor
<-
cor
(
pca.fuzz
$
CA
$
u
,
RDA.beals
$
CCA
$
u
[,
1
:
3
]))
#RDA.beals$CCA$biplot #
#
(fuzz.cor <- cor(pca.fuzz$CA$u, RDA.beals$CCA$u[,1:3])) #RDA.beals$CCA$biplot #
#
myvectors.rda
<-
as.data.frame
(
env.cor
)
%>%
#
myvectors.rda <- as.data.frame(env.cor) %>%
rownames_to_column
(
"mylab"
)
%>%
#
rownames_to_column("mylab") %>%
mutate
(
category
=
"Env"
)
%>%
#
mutate(category="Env") %>%
bind_rows
(
as.data.frame
(
cwms.cor
)
%>%
#
bind_rows(as.data.frame(cwms.cor) %>%
rownames_to_column
(
"mylab"
)
%>%
#
rownames_to_column("mylab") %>%
mutate
(
category
=
"Trait"
))
%>%
#
mutate(category="Trait")) %>%
bind_rows
(
as.data.frame
(
fuzz.cor
)
%>%
#
bind_rows(as.data.frame(fuzz.cor) %>%
rownames_to_column
(
"mylab"
)
%>%
#
rownames_to_column("mylab") %>%
mutate
(
mylab
=
paste0
(
"FWM-"
,
mylab
))
%>%
#
mutate(mylab=paste0("FWM-", mylab)) %>%
mutate
(
category
=
"Fuzzy-Weighted"
))
%>%
#
mutate(category="Fuzzy-Weighted")) %>%
mutate
(
fontface0
=
ifelse
(
mylab
%in%
best.traits.cov
,
"bold"
,
"italic"
))
%>%
#
mutate(fontface0=ifelse(mylab %in% best.traits.cov, "bold", "italic")) %>%
mutate
(
category
=
as.factor
(
category
))
%>%
#
mutate(category=as.factor(category)) %>%
mutate
(
mycol
=
ifelse
(
category
==
"Trait"
,
oilgreen
,
orange
))
%>%
#
mutate(mycol=ifelse(category=="Trait", oilgreen, orange)) %>%
mutate
(
mycol
=
ifelse
(
category
==
"Fuzzy-Weighted"
,
myblue
,
mycol
))
%>%
#
mutate(mycol=ifelse(category=="Fuzzy-Weighted", myblue, mycol)) %>%
mutate
(
categorical
=
ifelse
(
grepl
(
pattern
=
paste
(
categorical.traits
,
collapse
=
"|"
),
mylab
),
1
,
0
))
%>%
#
mutate(categorical=ifelse(grepl(pattern=paste(categorical.traits, collapse="|"), mylab), 1, 0)) %>%
rowwise
()
%>%
#
rowwise() %>%
mutate
(
mylab
=
gsub
(
pattern
=
"LeafPersistence"
,
replacement
=
"LeafPers"
,
x
=
mylab
))
#
mutate(mylab=gsub(pattern="LeafPersistence", replacement = "LeafPers", x = mylab))
#
#
#
basemap0
<-
ggplot
(
data
=
as.data.frame
(
scores.rda
))
+
#
basemap0 <- ggplot(data=as.data.frame(scores.rda)) +
theme_bw
()
+
#
theme_bw() +
scale_color_identity
()
+
#
scale_color_identity() +
scale_y_continuous
(
limits
=
c
(
-1
,
1
))
+
#
scale_y_continuous(limits=c(-1, 1)) +
scale_x_continuous
(
limits
=
c
(
-1
,
1
))
+
coord_equal
()
+
#
scale_x_continuous(limits=c(-1, 1)) + coord_equal() +
theme
(
panel.grid
=
element_blank
())
#
theme(panel.grid = element_blank())
#
#
RDA1_2
<-
basemap0
+
#
RDA1_2 <- basemap0 +
geom_point
(
data
=
as.data.frame
(
scores.rda
),
#
geom_point(data=as.data.frame(scores.rda),
aes
(
x
=
RDA1
,
y
=
RDA2
),
pch
=
"+"
,
size
=
2
,
alpha
=
0.8
)
+
#
aes(x=RDA1, y=RDA2), pch="+", size=2, alpha=0.8) +
geom_segment
(
data
=
myvectors.rda
%>%
#
geom_segment(data=myvectors.rda %>%
filter
(
categorical
==
0
),
#
filter(categorical==0),
aes
(
x
=
0
,
xend
=
RDA1
,
y
=
0
,
yend
=
RDA2
,
col
=
mycol
),
#
aes(x=0, xend=RDA1, y=0, yend=RDA2, col=mycol),
arrow
=
arrow
(
length
=
unit
(
0.08
,
"inches"
)),
alpha
=
0.8
)
+
#
arrow = arrow(length = unit(0.08, "inches")), alpha=0.8) +
geom_path
(
data
=
dat
,
aes
(
x
,
y
),
col
=
gray
(
0.8
),
lwd
=
0.5
)
+
#add correlation circle
#
geom_path(data=dat,aes(x,y), col=gray(0.8), lwd=0.5) + #add correlation circle
geom_label_repel
(
data
=
myvectors.rda
,
#
geom_label_repel(data=myvectors.rda,
aes
(
x
=
RDA1
,
y
=
RDA2
,
label
=
mylab
,
col
=
mycol
,
fontface
=
fontface0
),
size
=
2
,
#
aes(x=RDA1, y=RDA2, label=mylab, col=mycol, fontface=fontface0), size=2,
position
=
position_dodge
(
1
),
segment.alpha
=
0.5
,
segment.colour
=
gray
(
0.8
))
+
#
position = position_dodge(1), segment.alpha=0.5, segment.colour=gray(0.8)) +
xlab
(
paste
(
"RDA1 ("
,
varexpl
[
1
],
"%)"
,
sep
=
""
))
+
#
xlab(paste("RDA1 (", varexpl[1], "%)", sep="")) +
ylab
(
paste
(
"RDA2 ("
,
varexpl
[
2
],
"%)"
,
sep
=
""
))
#
ylab(paste("RDA2 (", varexpl[2], "%)", sep=""))
#
ggsave
(
"_pics/Fig6v2_RDA_Beals_1-2.png"
,
width
=
10
,
height
=
5
,
dpi
=
300
,
RDA1_2
)
#
ggsave("_pics/Fig6v2_RDA_Beals_1-2.png", width=10, height=5, dpi=300, RDA1_2)
#
#
RDA1_3
<-
basemap0
+
#
RDA1_3 <- basemap0 +
geom_point
(
data
=
as.data.frame
(
scores.rda
),
#
geom_point(data=as.data.frame(scores.rda),
aes
(
x
=
RDA1
,
y
=
RDA3
),
pch
=
"+"
,
size
=
2
,
alpha
=
0.8
)
+
#
aes(x=RDA1, y=RDA3), pch="+", size=2, alpha=0.8) +
geom_segment
(
data
=
myvectors.rda
%>%
#
geom_segment(data=myvectors.rda %>%
filter
(
categorical
==
0
),
#
filter(categorical==0),
aes
(
x
=
0
,
xend
=
RDA1
,
y
=
0
,
yend
=
RDA3
,
col
=
mycol
),
#
aes(x=0, xend=RDA1, y=0, yend=RDA3, col=mycol),
arrow
=
arrow
(
length
=
unit
(
0.08
,
"inches"
)),
alpha
=
0.8
)
+
#
arrow = arrow(length = unit(0.08, "inches")), alpha=0.8) +
geom_path
(
data
=
dat
,
aes
(
x
,
y
),
col
=
gray
(
0.8
),
lwd
=
0.5
)
+
#add correlation circle
#
geom_path(data=dat,aes(x,y), col=gray(0.8), lwd=0.5) + #add correlation circle
geom_label_repel
(
data
=
myvectors.rda
,
#
geom_label_repel(data=myvectors.rda,
aes
(
x
=
RDA1
,
y
=
RDA3
,
label
=
mylab
,
col
=
mycol
,
fontface
=
fontface0
),
size
=
2
,
#
aes(x=RDA1, y=RDA3, label=mylab, col=mycol, fontface=fontface0), size=2,
position
=
position_dodge
(
1
),
segment.alpha
=
0.5
,
segment.colour
=
gray
(
0.8
))
+
#
position = position_dodge(1), segment.alpha=0.5, segment.colour=gray(0.8)) +
xlab
(
paste
(
"RDA1 ("
,
varexpl
[
1
],
"%)"
,
sep
=
""
))
+
#
xlab(paste("RDA1 (", varexpl[1], "%)", sep="")) +
ylab
(
paste
(
"RDA3 ("
,
varexpl
[
3
],
"%)"
,
sep
=
""
))
#
ylab(paste("RDA3 (", varexpl[3], "%)", sep=""))
#
panel.RDA_beals
<-
cowplot
::
plot_grid
(
RDA1_2
,
RDA1_3
,
nrow
=
1
)
#
panel.RDA_beals <- cowplot::plot_grid(RDA1_2,RDA1_3, nrow=1)
#
ggsave
(
"_pics/Fig6v2_RDA_Beals_1-2-3.png"
,
width
=
10
,
height
=
5
,
dpi
=
300
,
panel.RDA_beals
)
#
ggsave("_pics/Fig6v2_RDA_Beals_1-2-3.png", width=10, height=5, dpi=300, panel.RDA_beals)
#
#### 4.2.1 Alternative showing species scores ####
#
#### 4.2.1 Alternative showing species scores ####
tmp
<-
as.data.frame
(
scores
(
RDA.beals
,
choices
=
1
:
3
)
$
species
*
4
)
%>%
#
tmp <- as.data.frame(scores(RDA.beals, choices = 1:3)$species*4) %>%
#tmp <- as.data.frame(RDA.beals$CCA$v*4) %>%
#
#tmp <- as.data.frame(RDA.beals$CCA$v*4) %>%
mutate
(
species0
=
rownames
(
RDA.beals
$
CCA
$
v
))
%>%
#
mutate(species0=rownames(RDA.beals$CCA$v)) %>%
mutate
(
species
=
species0
)
%>%
#
mutate(species=species0) %>%
separate
(
species0
,
sep
=
"_"
,
into
=
c
(
"Gen"
,
"Spe"
))
%>%
#
separate(species0, sep="_", into=c("Gen", "Spe")) %>%
mutate
(
Gen
=
substr
(
Gen
,
1
,
3
))
%>%
#
mutate(Gen=substr(Gen, 1, 3)) %>%
mutate
(
Spe
=
substr
(
Spe
,
1
,
3
))
%>%
#
mutate(Spe=substr(Spe, 1, 3)) %>%
mutate
(
labels
=
paste
(
Gen
,
Spe
,
sep
=
"_"
))
#
mutate(labels=paste(Gen, Spe, sep="_"))
#
tmp
<-
fix.duplicate.labels
(
tmp
)
#
tmp <- fix.duplicate.labels(tmp)
#
#
RDA1_2.sp
<-
basemap0
%+%
tmp
+
#
RDA1_2.sp <- basemap0 %+% tmp +
geom_text
(
aes
(
x
=
RDA1
,
y
=
RDA2
,
label
=
labels
),
size
=
2
,
alpha
=
0.8
)
+
#
geom_text(aes(x=RDA1, y=RDA2, label=labels), size=2, alpha=0.8) +
geom_segment
(
data
=
myvectors.rda
%>%
#
geom_segment(data=myvectors.rda%>%
filter
(
categorical
==
0
),
#
filter(categorical==0),
aes
(
x
=
0
,
xend
=
RDA1
,
y
=
0
,
yend
=
RDA2
,
col
=
mycol
),
#
aes(x=0, xend=RDA1, y=0, yend=RDA2, col=mycol),
arrow
=
arrow
(
length
=
unit
(
0.08
,
"inches"
)),
alpha
=
0.8
)
+
#
arrow = arrow(length = unit(0.08, "inches")), alpha=0.8) +
geom_path
(
data
=
dat
,
aes
(
x
,
y
),
col
=
gray
(
0.8
),
lwd
=
0.5
)
+
#add correlation circle
#
geom_path(data=dat,aes(x,y), col=gray(0.8), lwd=0.5) + #add correlation circle
geom_label_repel
(
data
=
myvectors.rda
,
#
geom_label_repel(data=myvectors.rda,
aes
(
x
=
RDA1
,
y
=
RDA2
,
label
=
mylab
,
col
=
mycol
,
fontface
=
fontface0
),
size
=
2
,
#
aes(x=RDA1, y=RDA2, label=mylab, col=mycol, fontface=fontface0), size=2,
position
=
position_dodge
(
1
),
segment.alpha
=
0.5
,
segment.colour
=
gray
(
0.8
))
+
#
position = position_dodge(1), segment.alpha=0.5, segment.colour=gray(0.8)) +
xlab
(
paste
(
"RDA1 ("
,
varexpl
[
1
],
"%)"
,
sep
=
""
))
+
#
xlab(paste("RDA1 (", varexpl[1], "%)", sep="")) +
ylab
(
paste
(
"RDA2 ("
,
varexpl
[
2
],
"%)"
,
sep
=
""
))
#
ylab(paste("RDA2 (", varexpl[2], "%)", sep=""))
#
RDA1_3.sp
<-
basemap0
%+%
tmp
+
#
RDA1_3.sp <- basemap0 %+% tmp +
geom_text
(
aes
(
x
=
RDA1
,
y
=
RDA3
,
label
=
labels
),
size
=
2
,
alpha
=
0.8
)
+
#
geom_text(aes(x=RDA1, y=RDA3, label=labels), size=2, alpha=0.8) +
geom_segment
(
data
=
myvectors.rda
%>%
#
geom_segment(data=myvectors.rda%>%
filter
(
categorical
==
0
),
#
filter(categorical==0),
aes
(
x
=
0
,
xend
=
RDA1
,
y
=
0
,
yend
=
RDA3
,
col
=
mycol
),
#
aes(x=0, xend=RDA1, y=0, yend=RDA3, col=mycol),
arrow
=
arrow
(
length
=
unit
(
0.08
,
"inches"
)),
alpha
=
0.8
)
+
#
arrow = arrow(length = unit(0.08, "inches")), alpha=0.8) +
geom_path
(
data
=
dat
,
aes
(
x
,
y
),
col
=
gray
(
0.8
),
lwd
=
0.5
)
+
#add correlation circle
#
geom_path(data=dat,aes(x,y), col=gray(0.8), lwd=0.5) + #add correlation circle
geom_label_repel
(
data
=
myvectors.rda
,
#
geom_label_repel(data=myvectors.rda,
aes
(
x
=
RDA1
,
y
=
RDA3
,
label
=
mylab
,
col
=
mycol
,
fontface
=
fontface0
),
size
=
2
,
#
aes(x=RDA1, y=RDA3, label=mylab, col=mycol, fontface=fontface0), size=2,
position
=
position_dodge
(
1
),
segment.alpha
=
0.8
,
segment.colour
=
gray
(
0.7
),
segment.size
=
0.5
)
+
#
position = position_dodge(1), segment.alpha=0.8, segment.colour=gray(0.7), segment.size = 0.5) +
xlab
(
paste
(
"RDA1 ("
,
varexpl
[
1
],
"%)"
,
sep
=
""
))
+
#
xlab(paste("RDA1 (", varexpl[1], "%)", sep="")) +
ylab
(
paste
(
"RDA3 ("
,
varexpl
[
3
],
"%)"
,
sep
=
""
))
#
ylab(paste("RDA3 (", varexpl[3], "%)", sep=""))
#
#
ggsave
(
"_pics/Fig6v2a_RDA_Beals_1-2_wSpecies.png"
,
width
=
8
,
height
=
8
,
dpi
=
300
,
RDA1_2.sp
)
#
ggsave("_pics/Fig6v2a_RDA_Beals_1-2_wSpecies.png", width=8, height=8, dpi=300, RDA1_2.sp)
ggsave
(
"_pics/Fig6v2b_RDA_Beals_1-3_wSpecies.png"
,
width
=
8
,
height
=
8
,
dpi
=
300
,
RDA1_3.sp
)
#
ggsave("_pics/Fig6v2b_RDA_Beals_1-3_wSpecies.png", width=8, height=8, dpi=300, RDA1_3.sp)
#
...
...
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