### Install and Load ggNetView R Package Source: https://github.com/bolinho9ue/ggnetview/blob/main/README.md Installs and loads the ggNetView package in R. Requires the package file to be available locally. Assumes R version 4.0 or later. ```R install.packages("path/to/ggNetView_unicarinate.zip") library(ggNetView) ``` -------------------------------- ### Multi-Orientation Environment-Species Heatmaps Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Prepares environmental data for creating integrated visualizations linking species networks with environmental correlations. This example shows the creation of a sample environmental data frame. ```r # Prepare environmental data env_data <- data.frame( matrix(rnorm(100 * 20), nrow = 100, ncol = 20) ) colnames(env_data) <- paste0("Env_", 1:20) ``` -------------------------------- ### Create Multi-Orientation Heatmap with ggNetView (Correlation) Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Generates multi-orientation heatmap visualizations using gglink_heatmaps. This example uses correlation as the relation_method, with Spearman correlation, and specifies various orientations and plotting parameters. ```r heatmap_plots <- gglink_heatmaps( env = env_data, spec = species_data, env_select = env_groups, spec_select = spec_groups, spec_layout = "ringle", relation_method = "correlation", cor.method = "spearman", cor.use = "pairwise", drop_nonsig = FALSE, shape = 22, distance = 4, orientation = c("top_right", "bottom_right", "top_left", "bottom_left"), r = 6 ) ``` -------------------------------- ### Create Heatmap with ggNetView (Mantel Test) Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Generates a heatmap visualization using gglink_heatmaps with the mantel test as the relation_method. This example specifies mantel test parameters and a subset of orientations. ```r heatmap_mantel <- gglink_heatmaps( env = env_data, spec = species_data, env_select = env_groups, spec_select = spec_groups, relation_method = "mantel", mantel.method = "mantel", mantel.method2 = "spearman", mantel.alternative = "two.sided", orientation = c("top_right", "bottom_left"), r = 8 ) ``` -------------------------------- ### Prepare Species Data for ggNetView Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Prepares species abundance data by selecting the first 8 columns and renaming them to 'Spec_1' through 'Spec_8'. This ensures the data is in the correct format for the ggNetView functions. ```r species_data <- data.frame(abundance_mat[, 1:8]) colnames(species_data) <- paste0("Spec_", 1:8) ``` -------------------------------- ### ggNetView: Gephi-style Layout with Module Organization Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Creates a network plot with a Gephi-style layout, organizing nodes by modules. Allows for label display, outer borders, and control over point size and orientation. ```r p4 <- ggNetView( graph_obj = graph_obj, layout = "gephi", layout.module = "adjacent", k_nn = 10, label = TRUE, labelsize = 5, add_outer = TRUE, shape = 22, pointsize = c(4, 14), orientation = "up", seed = 1115 ) ``` -------------------------------- ### Import Network Data in R Source: https://github.com/bolinho9ue/ggnetview/blob/main/README.md Imports network data from a CSV file into the ggNetView package. The function expects a valid file path to the CSV. Output is a network object ready for visualization. ```R my_network <- read.csv("path/to/your_network_data.csv") ``` -------------------------------- ### ggNetView: Petal Layout with Labels and Outer Borders Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Visualizes a network using a petal layout with specified radius, label display, and outer border styling. It controls point appearance and seed for reproducibility. ```r p2 <- ggNetView( graph_obj = graph_obj, layout = "petal", r = 1.5, label = TRUE, labelsize = 4, add_outer = TRUE, outerwidth = 1.5, outerlinetype = 2, outeralpha = 0.3, pointalpha = 0.8, pointsize = c(3, 10), seed = 1115 ) ``` -------------------------------- ### Build Network from WGCNA Results in R Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Generates a network graph from WGCNA Topological Overlap Matrix (TOM) and module assignment data. It allows for optional node annotations and supports directed/undirected graphs. Dependencies include the 'ggNetView' package. ```r # Simulate WGCNA output wgcna_edges <- data.frame( from = rep(paste0("Gene_", 1:20), each = 5), to = paste0("Gene_", sample(1:20, 100, replace = TRUE)), weight = runif(100, 0.1, 0.9) ) wgcna_modules <- data.frame( ID = paste0("Gene_", 1:20), Module = sample(c("blue", "red", "green", "yellow"), 20, replace = TRUE) ) # Build network from WGCNA graph_wgcna <- build_graph_from_wgcna( wgcna_tom = wgcna_edges, module = wgcna_modules, directed = FALSE, seed = 1115 ) # With additional annotations gene_annotation <- data.frame( name = paste0("Gene_", 1:20), Pathway = sample(c("Metabolism", "Signaling", "Transport"), 20, replace = TRUE), Expression = rnorm(20, mean = 5, sd = 2) ) graph_wgcna_full <- build_graph_from_wgcna( wgcna_tom = wgcna_edges, module = wgcna_modules, node_annotation = gene_annotation, directed = FALSE ) ``` -------------------------------- ### ggNetView: Circular Rings Layout for Hierarchical Visualization Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Visualizes hierarchical data using a circular rings layout. Configurable parameters include the number of rings, radius, point shape, size, node label size, and line alpha. ```r p5 <- ggNetView( graph_obj = graph_obj, layout = "rings", ring_n = 5, r = 1.2, shape = 21, pointalpha = 0.85, pointsize = c(3, 12), nodelabsize = 3, linealpha = 0.25, orientation = "up" ) ``` -------------------------------- ### Visualize Network in R using ggNetView Source: https://github.com/bolinho9ue/ggnetview/blob/main/README.md Generates a network visualization using the imported network data. Requires the network object to be previously loaded. The output is a plot object. ```R plot_network(my_network) ``` -------------------------------- ### Build Network from Correlation Matrix in R Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Constructs a network graph from a numeric abundance matrix using WGCNA, SpiecEasi, or correlation-based methods. It supports various transformation, correlation, and module detection algorithms, and allows for node annotations. Dependencies include the 'ggNetView' package and potentially others like 'WGCNA' or 'SpiecEasi'. ```r library(ggNetView) # Create sample microbiome abundance matrix (samples x features) set.seed(1115) abundance_mat <- matrix( rpois(100 * 50, lambda = 10), nrow = 100, ncol = 50 ) colnames(abundance_mat) <- paste0("Species_", 1:50) # Build correlation-based network with WGCNA method graph_obj <- build_graph_from_mat( mat = abundance_mat, transfrom.method = "log2", r.threshold = 0.7, p.threshold = 0.05, method = "WGCNA", cor.method = "spearman", proc = "BH", module.method = "Fast_greedy", top_modules = 10, seed = 1115 ) # Build network using SpiecEasi for sparse compositional data graph_obj_spiec <- build_graph_from_mat( mat = abundance_mat, method = "SpiecEasi", SpiecEasi.method = "mb", module.method = "Walktrap", top_modules = 15 ) # Add node annotations node_annotation <- data.frame( name = paste0("Species_", 1:50), Phylum = sample(c("Firmicutes", "Bacteroidetes", "Proteobacteria"), 50, replace = TRUE), Function = sample(c("Degrader", "Producer", "Symbiont"), 50, replace = TRUE) ) graph_obj_annotated <- build_graph_from_mat( mat = abundance_mat, method = "cor", cor.method = "pearson", r.threshold = 0.6, p.threshold = 0.01, node_annotation = node_annotation, top_modules = 12 ) ``` -------------------------------- ### Build Network from Data Frame in R Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Constructs a network graph from an edge list data frame, which can include edge weights. It supports directed and undirected graphs and allows for node annotations. Various module detection algorithms can be applied. Dependencies include the 'ggNetView' package. ```r # Create edge list data frame edges <- data.frame( from = c("A", "A", "B", "B", "C", "D", "E", "F"), to = c("B", "C", "C", "D", "E", "E", "F", "A"), weight = c(0.8, 0.75, 0.9, 0.65, 0.7, 0.85, 0.6, 0.72) ) # Build simple network graph_simple <- build_graph_from_df( df = edges, directed = FALSE, module.method = "Fast_greedy", top_modules = 5, seed = 1115 ) # Build network with node annotations node_info <- data.frame( name = LETTERS[1:6], type = c("TypeI", "TypeI", "TypeII", "TypeII", "TypeIII", "TypeIII"), importance = c(10, 8, 12, 9, 11, 7) ) graph_annotated <- build_graph_from_df( df = edges, node_annotation = node_info, directed = FALSE, module.method = "Walktrap", top_modules = 3 ) # Build directed network with edge betweenness clustering graph_directed <- build_graph_from_df( df = edges, directed = TRUE, module.method = "Edge_betweenness", top_modules = 10 ) ``` -------------------------------- ### Save Network Graph in R Source: https://github.com/bolinho9ue/ggnetview/blob/main/README.md Saves the generated network graph to a file. Supports various formats depending on the underlying plotting library. Requires a filename as input. ```R ggsave("network_visualization.png") ``` -------------------------------- ### ggNetView: Heart-Centered Layout with Custom Styling Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Generates a network visualization using a heart-centered layout with custom point shapes, sizes, and line styling. Includes jittering for overlapping points and option to remove nodes. ```r p3 <- ggNetView( graph_obj = graph_obj, layout = "heart_centered", shape = 21, pointalpha = 0.9, pointsize = c(2, 15), pointstroke = 0.5, mapping_line = TRUE, linealpha = 0.3, linecolor = "grey60", jitter = TRUE, jitter_sd = 0.05, remove = TRUE, seed = 1115 ) ``` -------------------------------- ### Visualize Network with Custom Layouts in R Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Generates publication-quality network visualizations using ggplot2 and ggraph. It supports various graph objects created by ggNetView functions and offers extensive customization options for layouts, node shapes, sizes, and colors. Dependencies include 'ggNetView', 'ggplot2', and 'ggraph'. ```r # Basic star layout visualization p1 <- ggNetView( graph_obj = graph_obj, layout = "star", shape = 21, pointsize = c(2, 12), seed = 1115 ) ``` -------------------------------- ### Random Matrix Theory Threshold Selection Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Automatically determines optimal correlation threshold for network construction using Random Matrix Theory. It analyzes eigenvalue statistics and generates plots to justify the chosen threshold. ```r # Create correlation matrix cor_matrix <- cor(t(abundance_mat), method = "spearman") # Run RMT analysis with plot generation rmt_result <- ggNetView_RMT( mat = cor_matrix, nr_thresholds = 51, unfold.method = "gaussian", discard.outliers = TRUE, discard.zeros = TRUE, min.mat.dim = 40, save_plots = TRUE, out_dir = "RMT_analysis", verbose = TRUE ) # Access recommended threshold optimal_threshold <- rmt_result$chosen_threshold cat("Optimal threshold:", optimal_threshold, "\n") cat("Selection reason:", rmt_result$chosen_reason, "\n") # View threshold scan results print(head(rmt_result$scores)) # threshold eff_dim nr_zeros nr_spacings kld_exp kld_wig ks_p sse_exp # 1 0.3500 245 128475 244 0.045123 0.234567 0.12345 0.00234 # 2 0.4000 198 145632 197 0.032456 0.198234 0.23456 0.00198 # 3 0.4500 156 162789 155 0.028901 0.176543 0.34567 0.00167 # Build network using RMT-selected threshold graph_rmt_optimal <- build_graph_from_mat( mat = abundance_mat, method = "cor", cor.method = "spearman", r.threshold = optimal_threshold, p.threshold = 0.05, module.method = "Fast_greedy" ) ``` -------------------------------- ### Extract Module Subgraphs Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Extracts individual module subgraphs from a modularized network using `get_subgraph`. Allows for visualization of individual modules and analysis of their specific topology and structural properties. ```r # Extract all modules as separate subgraphs subgraphs <- get_subgraph(graph_obj) # Access individual modules module_1 <- subgraphs[["1"]] module_2 <- subgraphs[["2"]] # Visualize individual modules p_module1 <- ggNetView( graph_obj = module_1, layout = "circle", shape = 21, pointsize = c(3, 10), label = FALSE, seed = 1115 ) # Analyze module-specific topology topology_module1 <- get_network_topology(module_1) # Iterate through all modules for systematic analysis module_stats <- lapply(names(subgraphs), function(mod_name) { subgraph <- subgraphs[[mod_name]] nodes <- tidygraph::as_tibble(tidygraph::activate(subgraph, nodes)) edges <- tidygraph::as_tibble(tidygraph::activate(subgraph, edges)) data.frame( module = mod_name, node_count = nrow(nodes), edge_count = nrow(edges), density = nrow(edges) / (nrow(nodes) * (nrow(nodes) - 1) / 2) ) }) module_summary <- do.call(rbind, module_stats) ``` -------------------------------- ### Compute Network Topology Metrics Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Calculates comprehensive network topology statistics including centrality measures and community structure using the `get_network_topology` function. The output can be used for filtering nodes based on importance. ```r # Calculate network topology topology <- get_network_topology(graph_obj) # Access topology metrics print(head(topology)) # degree_vals avg_path dia clust_global clust_local betweenness_vals # 1 15 2.1543 5.0 0.4523 0.5234 123.45 # 2 12 2.1543 5.0 0.4523 0.4891 98.23 # 3 18 2.1543 5.0 0.4523 0.6012 156.78 # closeness_vals eigen_vals fast_greedy_com_modularity # 1 0.4652 0.2341 0.5234 # 2 0.4523 0.1987 0.5234 # 3 0.4789 0.2876 0.5234 # Use topology for filtering important nodes important_nodes <- topology[topology$betweenness_vals > quantile(topology$betweenness_vals, 0.75), ] high_degree_nodes <- topology[topology$degree_vals > 10, ] ``` -------------------------------- ### Access ggNetView Heatmap Plot Versions Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Demonstrates how to access individual plot components from the list of heatmap plots generated by gglink_heatmaps. 'plot_straight_lines' and 'plot_curved_lines' are extracted for further manipulation or display. ```r plot_straight_lines <- heatmap_plots[[1]] plot_curved_lines <- heatmap_plots[[2]] ``` -------------------------------- ### Define Environmental and Species Groups for ggNetView Source: https://context7.com/bolinho9ue/ggnetview/llms.txt Defines lists for environmental variable groups (Env01-Env04) and species groups (Core_Species) used for subsetting data in ggNetView visualizations. These lists specify the indices for selecting relevant variables and species. ```r env_groups <- list( Env01 = 1:5, Env02 = 6:10, Env03 = 11:15, Env04 = 16:20 ) spec_groups <- list( Core_Species = 1:8 ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.