# Create a simple network
net <- data.frame(
Node1 = c("A", "A", "B", "C"),
Node2 = c("B", "C", "C", "D"),
Weight = c(1.5, 2.0, 1.0, 3.5)
)
# Export network with weights
if (FALSE) {
exportGDF(net, weight = "Weight", file = "my_network.gdf")
}
# Create bioregionalization data with colors (as data.frame)
bioregion_data <- data.frame(
node_id = c("A", "B", "C", "D"),
cluster = c("1", "2", "3", "4"),
node_color = c("#FF5733", "#33FF57", "#3357FF", "#FF33F5")
)
# Export network with bioregionalization and colors
if (FALSE) {
exportGDF(net,
weight = "Weight",
bioregions = bioregion_data,
bioregionalization = "node_id",
color_column = "node_color",
file = "my_network_with_bioregions.gdf")
}
# Using bioregion.clusters object with colors (recommended)
if (FALSE) {
data(fishmat)
net <- similarity(fishmat, metric = "Simpson")
clust <- netclu_greedy(net)
clust_colored <- bioregion_colors(clust)
# Convert to network format
net_df <- mat_to_net(fishmat, weight = TRUE)
# Export with automatic colors from clustering - very simple!
exportGDF(net_df,
weight = "weight",
bioregions = clust_colored,
file = "my_network_colored.gdf")
# With multiple partitions, specify which one to use
dissim <- similarity_to_dissimilarity(similarity(fishmat, metric = "Simpson"))
clust_hier <- hclu_hierarclust(dissim, n_clust = c(3, 5, 8))
clust_hier_colored <- bioregion_colors(clust_hier)
# Using partition name
exportGDF(net_df,
weight = "weight",
bioregions = clust_hier_colored,
bioregionalization = "K_5",
file = "my_network_K5.gdf")
# Or using partition index (2 = second partition)
exportGDF(net_df,
weight = "weight",
bioregions = clust_hier_colored,
bioregionalization = 2,
file = "my_network_partition2.gdf")
}
Run the code above in your browser using DataLab