library(igraph)
#>
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#>
#> decompose, spectrum
#> The following object is masked from 'package:base':
#>
#> union
# a graph
set.seed(44)
g <- barabasi.game(6)
# with weighted vertex
V(g)$w <- c(10, 50, 100, 10, 50, 100)
# and weighted edges
E(g)$fij <- c(20, 20, 50, 40, 5)
# fix layout
l <- layout_nicely(g)
# get proportional & normalized cicrles
get_vertex_weight <- function(x, w_max = 15) {
size <- sqrt((x * pi / max(x)) / pi)
size * w_max
}
# get normalized lines
get_edge_width <- function(x, w_max = 10) {
size <- (x / max(x))
size * w_max
}
v_w <- get_vertex_weight(x = V(g)$w, w_max = 50)
e_w <- get_edge_width(x = E(g)$fij, w_max = 20)
plot(g,
layout = l,
vertex.size = v_w,
edge.width = e_w,
vertex.color = "lightgreen",
edge.color = "lightblue",
rescale = TRUE)
library(maplegend)
leg(type = "prop",
val = c(10, 50, 100),
inches = max(v_w) / 200 / xinch(1),
lwd = 1,
title = 'Des Noeuds',
pos = "topleft" ,
horiz = TRUE,
col = "lightgreen")
leg(type = "prop_line",
val = c(5, 20, 50),
lwd = max(e_w),
title = "Des liens",
pos = "left" ,
col = "lightblue",
box_cex = c(3, .5))
###
leg_comp(type = "prop",
val = c(10, 50, 100),
inches = max(v_w) / 200 / xinch(1),
lwd = 1,
title = 'Des Noeuds',
horiz = FALSE,
col = "lightgreen") |>
leg_comp(type = "prop_line",
val = c(5, 20, 50),
lwd = max(e_w),
title = "Des liens",
col = "lightblue",
box_cex = c(3, .5)) |>
leg_draw(pos = "topright", frame_border = NA)
Created on 2023-10-04 with reprex v2.0.2