-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.R
75 lines (63 loc) · 1.75 KB
/
code.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
library(tidyverse)
library(worrrd)
df <- read_csv("wordlists.csv")
lang <- "Andi"
group <- "animals"
df |>
filter(group == group,
language == lang) |>
select(word_id, word) |>
mutate(word = toupper(word)) ->
words_for_crossword
c <- crossword(words = words_for_crossword$word,
clues = words_for_crossword$word,
r = 40, c = 40)
attr(c, "positions") |>
group_by(word) |>
slice(1) |>
ungroup() |>
count(i, j) |>
filter(n > 1) |>
rename(duplicates = n) ->
duplicates
attr(c, "clues") |>
left_join(duplicates) |>
left_join(words_for_crossword) |>
select(i, j, word_id, duplicates) |>
arrange(word_id) |>
group_by(i, j) |>
summarise(label = str_c(word_id, collapse = "/")) ->
labels
attr(c, "positions") |>
left_join(words_for_crossword) |>
left_join(duplicates) |>
ggplot(aes(x = j, y = i))+
geom_tile(fill = "grey85", color = "black", linewidth = 0.1)+
geom_text(aes(label = label),
size = 2, nudge_y = 0.35, nudge_x = -0.10,
data = labels)+
coord_fixed()+
scale_y_reverse()+
theme_void() ->
p
p
ggsave(plot = p,
filename = str_c("results/", lang, "_", group, ".png"),
bg = "white", width = 7, height = 7)
attr(c, "positions") |>
left_join(words_for_crossword) |>
left_join(duplicates) |>
ggplot(aes(x = j, y = i))+
geom_tile(fill = "grey85", color = "black", linewidth = 0.1)+
geom_text(aes(label = letters))+
geom_text(aes(label = label),
size = 2, nudge_y = 0.35, nudge_x = -0.10,
data = labels)+
coord_fixed()+
scale_y_reverse()+
theme_void() ->
a
a
ggsave(plot = a,
filename = str_c("answers/", lang, "_", group, ".png"),
bg = "white", width = 7, height = 7)