八卦
bagua<-function(){
sectors = 1:8
circos.par(start.degree = 22.5, gap.degree = 6)
circos.initialize(sectors, xlim = c(0, 1))
# yang yao is __ (a long segment)
add_yang_yao = function() {
circos.rect(0,0,1,1, col = "black")
}
# yin yao is -- (two short segments)
add_yin_yao = function() {
circos.rect(0,0,0.45,1, col = "black")
circos.rect(0.55,0,1,1, col = "black")
}
circos.track(ylim = c(0, 1), sectors = sectors, bg.border = NA,
panel.fun = function(x, y) {
i = get.cell.meta.data("sector.numeric.index")
if(i %in% c(2, 5, 7, 8)) add_yang_yao() else add_yin_yao()
}, track.height = 0.1)
circos.track(ylim = c(0, 1), sectors = sectors, bg.border = NA,
panel.fun = function(x, y) {
i = get.cell.meta.data("sector.numeric.index")
if(i %in% c(1, 6, 7, 8)) add_yang_yao() else add_yin_yao()
}, track.height = 0.1)
circos.track(ylim = c(0, 1), sectors = sectors, bg.border = NA,
panel.fun = function(x, y) {
i = get.cell.meta.data("sector.numeric.index")
if(i %in% c(4, 5, 6, 7)) add_yang_yao() else add_yin_yao()
}, track.height = 0.1)
}
bagua()
太极阴阳鱼
taiji<-function(){
sectors = 1:8
circos.par(start.degree = 22.5, gap.degree = 6)
circos.initialize(sectors, xlim = c(0, 1))
circos.track(ylim = c(0, 1), sectors = sectors, bg.border = NA,
)
# the bottom of the most recent track
r = get.cell.meta.data("cell.bottom.radius") - 0.1
# draw taiji, note default order is clock wise for `draw.sector`
draw.sector(center = c(0, 0), start.degree = 90, end.degree = -90,
rou1 = r, col = "black", border = "black")
draw.sector(center = c(0, 0), start.degree = 270, end.degree = 90,
rou1 = r, col = "white", border = "black")
draw.sector(center = c(0, r/2), start.degree = 0, end.degree = 360,
rou1 = r/2, col = "white", border = "white")
draw.sector(center = c(0, -r/2), start.degree = 0, end.degree = 360,
rou1 = r/2, col = "black", border = "black")
draw.sector(center = c(0, r/2), start.degree = 0, end.degree = 360,
rou1 = r/8, col = "black", border = "black")
draw.sector(center = c(0, -r/2), start.degree = 0, end.degree = 360,
rou1 = r/8, col = "white", border = "white")
}
taiji()
太极八卦图
taijibagua<-function(){
sectors = 1:8
circos.par(start.degree = 22.5, gap.degree = 6)
circos.initialize(sectors, xlim = c(0, 1))
# yang yao is __ (a long segment)
add_yang_yao = function() {
circos.rect(0,0,1,1, col = "black")
}
# yin yao is -- (two short segments)
add_yin_yao = function() {
circos.rect(0,0,0.45,1, col = "black")
circos.rect(0.55,0,1,1, col = "black")
}
circos.track(ylim = c(0, 1), sectors = sectors, bg.border = NA,
panel.fun = function(x, y) {
i = get.cell.meta.data("sector.numeric.index")
if(i %in% c(2, 5, 7, 8)) add_yang_yao() else add_yin_yao()
}, track.height = 0.1)
circos.track(ylim = c(0, 1), sectors = sectors, bg.border = NA,
panel.fun = function(x, y) {
i = get.cell.meta.data("sector.numeric.index")
if(i %in% c(1, 6, 7, 8)) add_yang_yao() else add_yin_yao()
}, track.height = 0.1)
circos.track(ylim = c(0, 1), sectors = sectors, bg.border = NA,
panel.fun = function(x, y) {
i = get.cell.meta.data("sector.numeric.index")
if(i %in% c(4, 5, 6, 7)) add_yang_yao() else add_yin_yao()
}, track.height = 0.1)
# the bottom of the most recent track
r = get.cell.meta.data("cell.bottom.radius") - 0.1
# draw taiji, note default order is clock wise for `draw.sector`
draw.sector(center = c(0, 0), start.degree = 90, end.degree = -90,
rou1 = r, col = "black", border = "black")
draw.sector(center = c(0, 0), start.degree = 270, end.degree = 90,
rou1 = r, col = "white", border = "black")
draw.sector(center = c(0, r/2), start.degree = 0, end.degree = 360,
rou1 = r/2, col = "white", border = "white")
draw.sector(center = c(0, -r/2), start.degree = 0, end.degree = 360,
rou1 = r/2, col = "black", border = "black")
draw.sector(center = c(0, r/2), start.degree = 0, end.degree = 360,
rou1 = r/8, col = "black", border = "black")
draw.sector(center = c(0, -r/2), start.degree = 0, end.degree = 360,
rou1 = r/8, col = "white", border = "white")
}
taijibagua()
参考这篇里面的动态弦图,哪天有空把太极旋转动起来R数据可视化20:弦图 - 简书 (jianshu.com)
Chapter 17 Make fun of the package | Circular Visualization in R (jokergoo.github.io)
下面是一些基础知识:
一个circos图由扇区(sectors)和轨道(tracks)组成。不同分类的数据在分布在不同的扇区上,同一个分类的多个维度的数据在不同的轨道上堆叠。一个扇区和一个轨道的交点就是一个单元格(cell、grid或者panel),是circos图中基本的绘图单位。
大多数图形都是由点、线、多边形等简单的元素组合而成。circlize可以在circos图中添加这样的低级图形,并且通过它们之间的不同组合实现各种复杂的图形。这一点可以使circlize具有更高的灵活性。
circlize包中有以下几个低级绘图函数:
circos.points():绘制点图;
circos.lines():绘制折线图;
circos.segments():绘制线段;
circos.rect():绘制矩形;
circos.polygon():绘制多边形;
circos.text():添加文本;
circos.axis()和circos.yaxis():绘制坐标轴;
以下函数绘制circos图中两个位置之间的链接:
circos.link()
以下函数绘制高级图形:
circos.barplot():绘制条形图;
circos.boxplot():绘制箱线图;
circos.violin():绘制小提琴图;
circos.heatmap():绘制圆形热土;
circos.raster():绘制栅格图;
circos.arrow():绘制圆形箭头;
以下函数排列circos图的圆形布局:
circos.initialize():分配扇区;
circos.track():在一个轨道上为不同单元格创建绘图区域;
circos.update():更新已经存在的单元格;
circos.par():设置或查看绘图参数,起始角度,轨道高度等;
circos.info():查看当前circos图的基本参数,扇区数据、轨道数目、当前绘图区域等;
circos.clear():重置图形参数和内部变量;