
image.png
# Sun Sep 05 12:59:47 2021 edit
# 字符编码:UTF-8
# R 版本:R 4.1.1 x64 for window 11
# cgh163email@163.com
# 个人笔记不负责任,拎了个梨🍐🍈
#.rs.restartR()
require(circlize)
rm(list = ls());gc()
dt1 <- read.csv('data-link.csv',encoding = 'UTF-8')[,-1]
head(dt1)
dev.off()
chordDiagram(dt1[,3:5])
dev.copy(png, "1.png");dev.off()
# Sun Sep 05 13:07:29 2021 --
dev.off()
chordDiagram(dt1[, 3:5],h.ratio=.8, #弧度
col = rainbow(table(dt1$Target)[3][[1]]) # 炫色
, self.link = 1, symmetric = F,
directional = 1#, diffHeight = -mm_h(2)
)
title("全国省际物流趋势")
abline(h = 0, lty = 2, col = "#00000080")
dev.copy(png, "3.png");dev.off()
# 构建示例数据
set.seed(999)
# 构造邻接矩阵
mat = matrix(sample(18, 18), 3, 6)
rownames(mat) = paste0("S", 1:3)
colnames(mat) = paste0("E", 1:6)
head(mat)
## E1 E2 E3 E4 E5 E6
## S1 4 14 13 17 5 2
## S2 7 1 6 8 12 15
## S3 9 10 3 16 11 18
# 构建邻接列表数据框
df = data.frame(from = rep(rownames(mat), times = ncol(mat)), #起始对象
to = rep(colnames(mat), each = nrow(mat)), #终止对象
value = as.vector(mat),#起始对象与终止对象之间的相互作用强度
stringsAsFactors = FALSE)
head(df)
## from to value
## 1 S1 E1 4
## 2 S2 E1 7
## 3 S3 E1 9
## 4 S1 E2 14
## 5 S2 E2 1
## 6 S3 E2 10
# 使用chordDiagram函数绘制和弦图
# 使用邻接矩阵绘图
chordDiagram(mat)
chordDiagram(df)
# 结束绘图,返回默认设置,否则会继续叠加图层
circos.clear()
网友评论