diff --git a/R/plot_simplified_edgeplot.R b/R/plot_simplified_edgeplot.R index d851967..d0c55c3 100644 --- a/R/plot_simplified_edgeplot.R +++ b/R/plot_simplified_edgeplot.R @@ -5,11 +5,40 @@ #' @param communities optional; A communities object #' @param ... other arguments to be passed to the `plot()` function #' @examples -#' # Create an igraph object -#' my_graph <- igraph::make_ring(10) -#' # Plot the simplified edge plot -#' plot_simplified_edgeplot(my_graph) +#'# Load the igraph package +#' library(igraph) +#' library(ig.degree.betweenness) +#' # Set parameters +#' num_nodes <- 17 # Number of nodes (adjust as needed) +#' initial_edges <- 1 # Starting edges for preferential attachment #' +#' # Create a directed, scale-free network using the Barabási-Albert model +#' g <- sample_pa(n = num_nodes, m = initial_edges, directed = TRUE) +#' +#' # Introduce additional edges to high-degree nodes to accentuate popularity differences +#' num_extra_edges <- 350 # Additional edges to create more popular nodes +#' set.seed(123) # For reproducibility +#' +#' for (i in 1:num_extra_edges) { +#' # Sample nodes with probability proportional to their degree (to reinforce popularity) +#' from <- sample(V(g), 1, prob = degree(g, mode = "in") + 1) # +1 to avoid zero probabilities +#' to <- sample(V(g), 1) +#' +#' # Ensure we don't add the same edge repeatedly unless intended, allowing self-loops +#' g <- add_edges(g, c(from, to)) +#' } +#' +#' # Add self-loops to a subset of nodes +#' num_self_loops <- 5 +#' for (i in 1:num_self_loops) { +#' node <- sample(V(g), 1) +#' g <- add_edges(g, c(node, node)) +#' } +#' +#' +#' g_ <- ig.degree.betweenness::prep_unlabeled_graph(g) +#' +#' ig.degree.betweenness::plot_simplified_edgeplot(g_,main="Simulated Data") #' @export plot_simplified_edgeplot <- function(graph, diff --git a/man/plot_simplified_edgeplot.Rd b/man/plot_simplified_edgeplot.Rd index fcf3495..56b1d9f 100644 --- a/man/plot_simplified_edgeplot.Rd +++ b/man/plot_simplified_edgeplot.Rd @@ -19,9 +19,38 @@ Plot Simplified Edgeplot This function generates a simplified edge plot of an igraph object, optionally highlighting communities if provided. } \examples{ -# Create an igraph object -my_graph <- igraph::make_ring(10) -# Plot the simplified edge plot -plot_simplified_edgeplot(my_graph) +# Load the igraph package +library(igraph) +library(ig.degree.betweenness) +# Set parameters +num_nodes <- 17 # Number of nodes (adjust as needed) +initial_edges <- 1 # Starting edges for preferential attachment +# Create a directed, scale-free network using the Barabási-Albert model +g <- sample_pa(n = num_nodes, m = initial_edges, directed = TRUE) + +# Introduce additional edges to high-degree nodes to accentuate popularity differences +num_extra_edges <- 350 # Additional edges to create more popular nodes +set.seed(123) # For reproducibility + +for (i in 1:num_extra_edges) { + # Sample nodes with probability proportional to their degree (to reinforce popularity) + from <- sample(V(g), 1, prob = degree(g, mode = "in") + 1) # +1 to avoid zero probabilities + to <- sample(V(g), 1) + + # Ensure we don't add the same edge repeatedly unless intended, allowing self-loops + g <- add_edges(g, c(from, to)) +} + +# Add self-loops to a subset of nodes +num_self_loops <- 5 +for (i in 1:num_self_loops) { + node <- sample(V(g), 1) + g <- add_edges(g, c(node, node)) +} + + +g_ <- ig.degree.betweenness::prep_unlabeled_graph(g) + +ig.degree.betweenness::plot_simplified_edgeplot(g_,main="Simulated Data") }