-
Notifications
You must be signed in to change notification settings - Fork 19
/
__coo_oscillo2.R
executable file
·47 lines (42 loc) · 1.25 KB
/
__coo_oscillo2.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
library(Momocs)
shapes[4] %>%
coo_dxy() %>%
dplyr::mutate(id=1:n()) %>%
tidyr::gather(key = "what", value="value", dx, dy) %>%
ggplot() +
aes(x=id, y=value, col=what) +
geom_line() +
theme_minimal() +
ylab("") + xlab("Points along outlines") +
guides(colour = guide_legend(""))
coo_oscillo
coo_oscillo2 <- function(coo, method=c("dxy", "radius", "tangent")[1]){
.check(any(method %in% c("dxy", "radius", "tangent")),
"unvalid method")
if (method=="radius"){
value=coo_centdist(coo)
df <- dplyr::tibble(value=value,
id=seq_along(value),
what="centroid_dist")
}
if (method=="tangent"){
value=coo_angle_tangent(coo)
df <- dplyr::tibble(value=value,
id=seq_along(value),
what="tangent_angle")
}
if (method=="dxy"){
tmp <- coo_dxy(coo)
df <- dplyr::tibble(value=c(tmp$dx, tmp$dy),
id=rep(seq_along(tmp$dx), 2),
what=rep(c("dx", "dy"), each=nrow(tmp)))
}
# now the gg
df %>% ggplot() +
aes(x=id, y=value, col=what) +
geom_line() +
theme_minimal() +
xlab("Points alongs ids") +
ylab("") +
guides(colour=guide_legend(""))
}