value <- rnorm(10, 10, 2)
nodes <- data.frame(
name = sample(LETTERS, 10),
value = value,
size = value,
symbol = sample(c("circle", "rect", "triangle"), 10, replace = TRUE),
grp = rep(c("grp1", "grp2"), 5),
stringsAsFactors = FALSE
)
value_edges <- sample(1:100, 20, replace = TRUE)
edges <- data.frame(
source = sample(nodes$name, 20, replace = TRUE),
target = sample(nodes$name, 20, replace = TRUE),
value = value_edges,
size = ceiling(value_edges / 20),
stringsAsFactors = FALSE
)
e_charts() |>
e_graph() |>
e_graph_nodes(nodes, name, value, size, grp, symbol) |>
e_graph_edges(edges, source, target, value, size) |>
e_tooltip()
# Use graphGL for larger networks
nodes <- data.frame(
name = paste0(LETTERS, 1:1000),
value = rnorm(1000, 10, 2),
size = rnorm(1000, 10, 2),
grp = rep(c("grp1", "grp2"), 500),
stringsAsFactors = FALSE
)
edges <- data.frame(
source = sample(nodes$name, 2000, replace = TRUE),
target = sample(nodes$name, 2000, replace = TRUE),
stringsAsFactors = FALSE
)
e_charts() |>
e_graph_gl() |>
e_graph_nodes(nodes, name, value, size, grp) |>
e_graph_edges(edges, source, target)
# Fixed node positions, and edge color by variable
nodes <- data.frame(
name = c("A", "B", "C", "D", "E"),
value = c("A", "B", "C", "D", "E"),
group = c("gr1", "gr1", "gr2", "gr2", "gr3"),
size = 3:7 * 10,
x = c(0, 200, 400, 600, 800),
y = c(100, 100, 200, 200, 0)
)
edges <- data.frame(
source = c("A", "B", "C", "D", "E"),
target = c("B", "C", "D", "E", "D"),
size = rep(3, 5),
color = c("red", "green", "blue", "yellow", "black")
)
e_charts() |>
e_graph(layout = "none", autoCurveness = TRUE) |>
e_graph_nodes(nodes, name, value, size, category = group, xpos = x, ypos = y) |>
e_graph_edges(edges, source, target, size = size, color = color) |>
e_tooltip()
Run the code above in your browser using DataLab