Untitled

 avatar
unknown
plain_text
9 months ago
783 B
35
Indexable
library(ggraph)
library(igraph)
library(patchwork)

create_graph <- \(weights, nodes, range_scaling = 60) {
  data.frame(
    w1 = rep('like', 4),
    w2 = c('apple', 'orange', 'pear', 'peach'),
    weight = weights
  ) |>
    graph_from_data_frame() |>
    ggraph(layout = "fr") +
      geom_edge_link(alpha = .25, aes(width = weight)) +
      geom_node_point(aes(size = nodes), color = "blue") + 
      geom_node_text(aes(label = name), repel = TRUE) +
      scale_edge_width(range = range(weights)/range_scaling, breaks = unique(weights)) +
      scale_size_continuous(range = range(nodes)/range_scaling, breaks = unique(nodes))
}

create_graph(c(40, 60, 80, 100), c(100, 100, 120, 140, 160)) +
  create_graph(c(140, 140, 160, 180), c(200, 200, 220, 240, 260))
Editor is loading...
Leave a Comment