There are two core functions that let you build graphs in echarts4r; e_graph and e_graph_gl. The latter is the webGL “version.”

Basic

Initialise your graph with e_charts then add nodes and edges with e_graph_nodes and e_graph_edges respectively.

value <- rnorm(10, 10, 2)

nodes <- data.frame(
  name = sample(LETTERS, 10),
  value = value,
  size = value,
  stringsAsFactors = FALSE
)

edges <- data.frame(
  source = sample(nodes$name, 20, replace = TRUE),
  target = sample(nodes$name, 20, replace = TRUE),
  stringsAsFactors = FALSE
)

e_charts() %>% 
  e_graph() %>% 
  e_graph_nodes(nodes, name, value, size) %>% 
  e_graph_edges(edges, source, target) %>% 
  e_tooltip()

Groups

The same but with groups.

value <- rnorm(10, 10, 2)

nodes <- data.frame(
  name = sample(LETTERS, 10),
  value = value,
  size = value,
  grp = rep(c("grp1", "grp2"), 5),
  stringsAsFactors = FALSE
)

edges <- data.frame(
  source = sample(nodes$name, 20, replace = TRUE),
  target = sample(nodes$name, 20, replace = TRUE),
  stringsAsFactors = FALSE
)

e_charts() %>% 
  e_graph() %>% 
  e_graph_nodes(nodes, name, value, size, grp) %>% 
  e_graph_edges(edges, source, target) %>% 
  e_tooltip()

Graph GL

Simply use e_graph_gl instead of e_graph.

flights <- read.csv(
  paste0("https://raw.githubusercontent.com/plotly/datasets/",
         "master/2011_february_aa_flight_paths.csv")
) %>% 
  dplyr::select(airport1, airport2)

airports <- read.csv(
  paste0("https://raw.githubusercontent.com/plotly/datasets/",
         "master/2011_february_us_airport_traffic.csv")
) %>% 
  dplyr::select(iata, cnt)

# remove airports with no flights
airp <- unique(c(as.character(flights$airport1), as.character(flights$airport2)))
airports <- airports %>% 
  dplyr::filter(iata %in% airp)

e_charts() %>% 
    e_graph_gl() %>% 
    e_graph_nodes(airports, iata, cnt) %>% 
    e_graph_edges(flights, airport1, airport2) %>% 
    e_tooltip()