-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotting_mean_tree_competition_field.R
59 lines (49 loc) · 1.75 KB
/
plotting_mean_tree_competition_field.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
library(siplab)
library(sepci)
library(tidyverse)
library(ggforce)
data <- valdepoza
# In our case we will have 3 different mean trees
meanTrees <- valdepoza$marks |>
group_by_if(function(x) is.factor(x) || is.character(x)) |>
summarize_all(~mean(.x))
all <- tibble(
i = numeric(),
x = numeric(),
y = numeric(),
index = numeric()
)
kernel <- bella
kerpar <- list(dbh_mark = "dbh",largestCrownRadiusMark = "largestCrownRadius")
select <- powlinear_sel
selpar <- list(ki=10, kj=0, p=1, r0=0, smark="largestCrownRadius")
for(i in 1:nrow(meanTrees)){
meanTree <- meanTrees[i,]
marksMod <- valdepoza$marks |> add_row(meanTree)
minX <- min(valdepoza$x)-1
maxX <- max(valdepoza$x)+1
minY <- min(valdepoza$y)-1
maxY <- max(valdepoza$y)+1
for(x in seq(minX,maxX,by=.5)){
for(y in seq(minY,maxY,by=.5)){
distAll <- crossdist(x,y,valdepoza$x,valdepoza$y)
competitorsIndexes <- select(meanTree,valdepoza$marks,distAll,rank(distAll),selpar)
print(sum(competitorsIndexes))
competitorsMarks <- valdepoza$marks[competitorsIndexes,]
competitorsX <- valdepoza$x[competitorsIndexes]
competitorsY <- valdepoza$y[competitorsIndexes]
distCompetitors <- distAll[competitorsIndexes]
index<- sum(kernel(meanTree,competitorsMarks,distCompetitors,rank(distCompetitors),kerpar))
all <- all |> add_row(i=i,x=x,y=y,index=index)
}
}
}
dataf_valdepoza <- valdepoza$marks |>
mutate(x = valdepoza$x) |>
mutate(y = valdepoza$y)
cbind(valdepoza$x,valdepoza$y,valdepoza$marks)
# Change filter for different mean tree
ggplot() +
geom_tile(data=all |> filter(i==3),aes(x=x, y=y,fill=index)) +
geom_circle(data=dataf_valdepoza, aes(x0=x, y0=y, r = largestCrownRadius)) +
geom_point(data=dataf_valdepoza, aes(x=x, y=y))