R 语言绘制网络图示例:
# 绘制网络图
library(igraph)
library(gcookbook)
m <- madmen[1:nrow(madmen) %% 2 ==1, ]
g <- graph.data.frame(m, directed=FALSE)
V(g)$name
plot(g, layout=layout.fruchterman.reingold,
vertex.size = 4,
vertex.lable = V(g)$name,
vertex.label.cex = 0.8,
vertex.label.dist = 0.4,
vertex.lable.color = "black")
绘制有向图:
# 绘制有向图
library(igraph)
library(gcookbook)
madmen2
g <- graph.data.frame(madmen2, directed=TRUE)
par(mar=c(0,0,0,0))
plot(g, layout=layout.fruchterman.reingold,
vertex.size = 4,
vertex.lable = V(g)$name,
vertex.label.cex = 0.8,
vertex.label.dist = 0.4,
edge.arrow.size = 0.5,
vertex.label.color = NA)
# 试试圆形布局
g <- graph.data.frame(madmen2, directed=FALSE)
par(mar=c(0,0,0,0))
plot(g, layout=layout.circle,
vertex.size = 8,
vertex.color = "#3498DB",
vertex.label = NA)
绘制谱系图:
# 绘制谱系图
library(gcookbook)
c2 <- subset(countries, Year==2009)
c2 <- c2[complete.cases(c2), ]
set.seed(201)
c2 < -c2[sample(1:nrow(c2),25), ]
c2
rownames(c2) <- c2$Name
c2 <- c2[,4:7]
c2
c3 <- scale(c2)
c3
hc <- hclust(dist(c3))
plot(hc)
plot(hc, hang = -1)