make_edgelist <- function(data, edge_attributes = NULL, from = "from", to = "to") {
if (inherits(data, "netlit_edgelist")) {
if (is_empty(edge_attributes) && ncol(data) > 2) {
edge_attributes <- names(data)[-(1:2)]
}
}
else {
data <- process_from_to_data(data, from, to)
}
edgelist <- pare_edgelist(data, edge_attributes)
graph <- igraph::graph_from_data_frame(edgelist, directed = TRUE)
edgelist$edge_betweenness <- igraph::edge_betweenness(graph)
class(edgelist) <- unique(c("netlit_edgelist", class(edgelist)))
return(edgelist)
}
pare_edgelist <- function(data, edge_attributes = NULL) {
if (!is_empty(edge_attributes)) {
if (!is_character(edge_attributes)) {
abort("'edge_attributes' should be a character vector of names of columns in the supplied dataset.")
}
if (!all(edge_attributes %in% names(data))) {
not_in_data <- setdiff(edge_attributes, names(data))
abort(paste0("All values supplied to 'edge_attributes' must be names of columns in the supplied dataset.\nValue(s) not in the dataset:\t",
paste0(not_in_data, collapse = ", ")))
}
data[!names(data) %in% c(attr(data, "from"), attr(data, "to"), edge_attributes)] <- NULL
}
else {
data[!names(data) %in% c(attr(data, "from"), attr(data, "to"))] <- NULL
}
return(data)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.