Как и Istrel, я бы также порекомендовал igraph.Возможно второе решение с ggplot ..
library(ggnetwork)
library(ggplot2)
library(igraph)
#sample data:
set.seed(1)
mat <- matrix(rbinom(50 * 5, 1, 0.1), ncol = 15, nrow = 100)
# This is not necessary for the example data. But in your case, if you want species as nodes you have to do a transpose:
#mat <- t(mat)
#### Optional! But usually there are often "empty cases" which you might want to remove:
# remove 0-sum-columns
mat <- mat[,apply(mat, 2, function(x) !all(x==0))]
# remove 0-sum-rows
mat <- mat[apply(mat, 1, function(x) !all(x==0)),]
# transform in term-term adjacency matrix
mat.t <- mat %*% t(mat)
##### calculate graph
g <- igraph::graph.adjacency(mat.t,mode="undirected",weighted=T,diag=FALSE)
# calculate coordinates (see https://igraph.org/r/doc/layout_.html for different layouts)
layout <- as.matrix(layout_with_lgl(g))
p<-ggplot(g, layout = layout, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges( color = "grey20", alpha = 0.2, size = 2) + # add e.g. curvature = 0.15 for curved edges
geom_nodes(size = (centralization.degree(g)$res +3) , color="darkolivegreen4", alpha = 1) +
geom_nodes(size = centralization.degree(g)$res , color="darkolivegreen2", alpha = 1) +
geom_nodetext(aes(label = vertex.names), size= 5) +
theme_blank()
p
введите описание изображения здесь
Используйте эстетику ggplot:
# calculate degree:
V(g)$Degree <- centralization.degree(g)$res
p<-ggplot(g, layout = layout, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges( color = "grey20", alpha = 0.2, size = 2) + # add e.g. curvature = 0.15 for curved edges
geom_nodes(aes(size = Degree) , color="darkolivegreen2", alpha = 1) +
scale_size_continuous(range = c(5, 16)) +
geom_nodetext(aes(label = vertex.names), size= 5) +
theme_blank()
p