-
Notifications
You must be signed in to change notification settings - Fork 0
/
ordinering.qmd
133 lines (113 loc) · 2.81 KB
/
ordinering.qmd
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
title: "Ordinering av NiN hovedtyper"
format: html
editor: visual
---
## Bakgrunn
Her ønsker jeg å gruppere NiN-hovedtyper etter noen variabler som er med på å avgjøre hvorden de evt kan overvåkes i et nasjonalt naturovervåkingsprogram. Datasettet hentes fra google sheets.
```{r setup}
library(tidyverse)
library(googlesheets4)
library(vegan)
library(ggord)
library(ggtext)
library(ggrepel)
```
```{r getData}
gs4_user()
dat <- googlesheets4::read_sheet("https://docs.google.com/spreadsheets/d/1_xtwyLeKByIObjxrZP2ApkwQB9_oGlLle3SwSFjL_cA/edit?gid=0#gid=0")
```
####
```{r prepData}
mat2 <- dat |>
column_to_rownames("hovedtype_NiN2_kode") |>
filter(arcticAlpine != "yes") |>
mutate(
distributionalRange = case_match(
distributionalRange,
"Broad" ~ 1,
.default = 0
),
dispersed = case_match(
patchiness,
"Dispersed" ~ 1,
.default = 0),
localDensity = case_match(
localDensity,
"High" ~ 1,
.default = 0),
successionalStage = case_match(
successionalStage,
"yes" ~ 1,
.default = 0),
spatiallyDynamic = case_match(
spatiallyDynamic,
"yes" ~ 1,
.default = 0),
coastal = case_match(
coastal,
"yes" ~ 1,
.default = 0),
marginal = case_match(
marginal,
"yes" ~ 1,
.default = 0),
flater = flater/max(flater)
) |>
select(flater,
distributionalRange,
dispersed,
localDensity,
successionalStage,
spatiallyDynamic,
coastal,
marginal)
mat <- mat2 |>
select(-marginal)
```
```{r}
#| fig-width: 10
#| fig-height: 10
#| eval: false
myOrd <- metaMDS(mat, trace = FALSE)
plot(myOrd, type = "n") |>
#points("sites", cex = 0.8, pch=21, col="red", bg="yellow") |>
text("species", cex=0.7, col="blue")
ordilabel(myOrd, dis="sites", cex=0.7, font=3, fill="hotpink", col="blue")
ordilabel(myOrd, dis="sp", font=1.2, priority=colSums(mat))
```
```{r}
pca1 <- stats::prcomp(mat)
ggord(pca1, obslab=T, labcol = "blue", veccol = "grey",
vec_ext=1.2,
size=3,
txt=3,
exp = c(0.1, 0.1))
ggsave("pca1.jpg")
```
Samme ordinering, bare uten de marginale typene (for å få mindre overlapp mellom punktene)
```{r}
mat2 <- mat2 |>
filter(marginal != 1) |>
select(-marginal)
pca2 <- stats::prcomp(mat2)
ggord(pca2, obslab=T, labcol = "blue", veccol = "grey",
vec_ext=1.2,
size=3,
txt=3,
exp = c(0.1, 0.1))
ggsave("pca2_margnalRemoved.jpg")
```
Lag en stilistisk figur basert på rank order
```{r}
pca2[["x"]] |>
as.data.frame() |>
select(PC1, PC2) |>
mutate(PC1x = row_number(PC1),
PC2x = row_number(PC2)) |>
rownames_to_column(var = "name") |>
ggplot(aes(PC1x, PC2x, label = name))+
geom_point(color = "red")+
geom_label_repel()
ggsave("pca-labels.jpg")
```