Monday, May 30, 2022

ggnet2: network visualization with ggplot2 via R-studio

Например, функция ggnet2 — это функция визуализации для построения сетевых объектов как объектов ggplot2. Он принимает любой объект, который можно привести к сетевому классу, включая матрицы смежности или инцидентности, списки ребер или однорежимные сетевые объекты igraph.

Хотя мне больше нравится

nodes <- read.csv("Data1-Media-Sample-NODES.csv", header=T, as.is=T) 

links <- read.csv("Data1-Media-Sample-EDGES.csv", header=T, as.is=T)

install.packages('igraph')  # build

library('igraph') 

net <- graph_from_data_frame(d=links, vertices=nodes, directed=T)


boris@boris-All-Series:~/RBASE$ cat rbaseNetwork.R

library(GGally)

library(network)

library(sna)

library(ggplot2)

# random graph

net = rgraph(10, mode = "graph", tprob = 0.5)

net = network(net, directed = FALSE)


# vertex names

network.vertex.names(net) = letters[1:10]

ggnet2(net)

ggnet2(net, node.size = 6, node.color = "black", edge.size = 1, edge.color = "grey")

ggnet2(net, mode = "circle")

ggnet2(net, mode = "kamadakawai")

ggnet2(net, mode = "fruchtermanreingold", layout.par = list(cell.jitter = 0.75))

ggnet2(net, mode = "target", layout.par = list(niter = 100))

net %v% "phono" = ifelse(letters[1:10] %in% c("a", "e", "i"), "vowel", "consonant")

ggnet2(net, color = "phono")














boris@boris-All-Series:~/RBASE$ cat rbaseNetwork1.R

library(GGally)
library(network)
library(sna)
library(ggplot2)
# random graph
net = rgraph(10, mode = "graph", tprob = 0.5)
net = network(net, directed = FALSE)

# vertex names
network.vertex.names(net) = letters[1:10]
ggnet2(net)
ggnet2(net, node.size = 6, node.color = "black", edge.size = 1, edge.color = "grey")
ggnet2(net, mode = "circle")
ggnet2(net, mode = "kamadakawai")
ggnet2(net, mode = "fruchtermanreingold", layout.par = list(cell.jitter = 0.75))
ggnet2(net, mode = "target", layout.par = list(niter = 100))
net %v% "phono" = ifelse(letters[1:10] %in% c("a", "e", "i"), "vowel", "consonant")

ggnet2(net, color = "phono")

ggnet2(net, alpha = "phono", alpha.legend = "Phonetics")
ggnet2(net, shape = "phono", shape.legend = "Phonetics")
ggnet2(net, color = "phono", color.legend = "Phonetics")
ggnet2(net, size = "degree", size.legend = "Centrality")

ggnet2(net, color = "phono", size = "degree") +
  guides(color = FALSE, size = FALSE)
# control the colors of the nodes
ggnet2(net, color = "phono") +
  scale_color_brewer("", palette = "Set1",
                     labels = c("consonant" = "C", "vowel" = "V"),
                     guide = guide_legend(override.aes = list(size = 6)))

# control the size of the nodes
ggnet2(net, size = "degree") +
  scale_size_discrete("", range = c(5, 10), breaks = seq(10, 2, -2))
ggnet2(net, color = "phono", legend.size = 12, legend.position = "bottom") +
  theme(panel.background = element_rect(color = "grey"))
































No comments:

Post a Comment