Skip to content

Commit

Permalink
add R-utils for creating association maps
Browse files Browse the repository at this point in the history
  • Loading branch information
ausgerechnet committed Nov 25, 2024
1 parent f3061e0 commit 619683a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions R-utils/association.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
library(tidyverse)
library(ggraph)
library(tidygraph)

associations.maps <- function(associations, discoursemes, measure){

g <- associations |>
filter(measure == "measure") |>
filter(score > 0) |>
select(node, candidate, score) |>
rename(from = node, to = candidate, weight = score) |>
left_join(discoursemes |> select(id, name), by = join_by(from == id)) |> mutate(from = name) |> select(- name) |>
left_join(discoursemes |> select(id, name), by = join_by(to == id)) |> mutate(to = name) |> select(- name)

g |>
as_tbl_graph(directed = FALSE) |>
ggraph(layout = "fr") +
geom_edge_link(aes(width = weight), color = "gray") +
geom_node_point() +
geom_node_text(aes(label = name), repel = TRUE) +
theme_void()
}

0 comments on commit 619683a

Please sign in to comment.